Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Command failed: node lib #52

Closed
ghost opened this issue Oct 31, 2016 · 9 comments
Closed

Error: Command failed: node lib #52

ghost opened this issue Oct 31, 2016 · 9 comments

Comments

@ghost
Copy link

ghost commented Oct 31, 2016

After adding:

    "env": {
      "browser": true
    }

I received the error:

Error: Command failed: node lib
module.js:474
throw err;
^

Error: Cannot find module

I cannot go past this step and I have went back and checked my code. Everything matches accordingly.

@verekia
Copy link
Owner

verekia commented Oct 31, 2016

You likely haven't compiled your src folder into the lib folder via Gulp / Babel before running node lib.

@ghost
Copy link
Author

ghost commented Oct 31, 2016

Doesn't gulp do this with build?

@verekia
Copy link
Owner

verekia commented Oct 31, 2016

Yes it does it, but maybe you're missing something in your Gulp file like prerequisite tasks.

@verekia
Copy link
Owner

verekia commented Oct 31, 2016

Compare the provided Gulp file with yours and you should find the difference :)

@ghost
Copy link
Author

ghost commented Oct 31, 2016

The provided Gulp file is finished for Section 7. But I compared with the gulp file on section 6 and my file is exact. I compared against section 6 because I just finished section 6 and am at the very top of section 7.

/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-console */

import gulp from 'gulp';
import babel from 'gulp-babel';
import eslint from 'gulp-eslint';
import del from 'del';
import { exec } from 'child_process';

const paths = {
  allSrcJs: 'src/**/*.js',
  gulpFile: 'gulpfile.babel.js',
  libDir: 'lib',
};

gulp.task('lint', () =>
  gulp.src([
    paths.allSrcJs,
    paths.gulpFile,
  ])
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError())
);

gulp.task('clean', () => del(paths.libDir));

gulp.task('build', ['lint', 'clean'], () =>
  gulp.src(paths.allSrcJs)
    .pipe(babel())
    .pipe(gulp.dest(paths.libDir))
);

gulp.task('main', ['build'], (callback) => {
  exec(`node ${paths.libDir}`, (error, stdout) => {
    console.log(stdout);
    return callback(error);
  });
});

gulp.task('watch', () => {
  gulp.watch(paths.allSrcJs, ['main']);
});

gulp.task('default', ['watch', 'main']);

@ghost
Copy link
Author

ghost commented Oct 31, 2016

I just kept going and since lib is not referenced after webpack the errors are gone. I am working on a windows machine so there could be an issue due to different environment.

@lxblvs
Copy link

lxblvs commented Oct 31, 2016

Same problem on a linux machine.

The weird bit in the error is

Error: Cannot find module '/home/alex/thingies/js-test/lib'

I have the lib module in the root. Is it something about the task ordering? Here is my gulpfile:

/* eslint-disable import/no-extraneous-dependencies */

import gulp from 'gulp';
import babel from 'gulp-babel';
import del from 'del';
import { exec } from 'child_process';
import eslint from 'gulp-eslint';


const paths = {
    allSrcJs: 'src/**/*.js',
    gulpFile: 'gulpfile.babel.js',
    libDir: 'lib',
};

gulp.task('clean', () =>
    del(paths.libDir)
);

gulp.task('build', ['lint', 'clean'], () =>
    gulp.src(paths.allSrcJs)
        .pipe(babel())
        .pipe(gulp.dest(paths.libDir))
);

gulp.task('main', ['build'], (callback) => {
    exec(`node ${paths.libDir}`, (error, stdout) => {
        console.log(stdout);
        return callback(error);
    });
});

gulp.task('watch', () => {
    gulp.watch([paths.allSrcJs, paths.gulpFile], ['main']);
});

gulp.task('default', ['watch', 'main']);

gulp.task('lint', () =>
    gulp.src([
        paths.allSrcJs,
    ])
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failAfterError())
);

@verekia
Copy link
Owner

verekia commented Oct 31, 2016

Okay, I was able to reproduce the issue.

The problem is that you need to go further in that chapter to reach a build-able state. It is still in the middle of setting things up, and the build is not expected to work at every intermediate state such as this one. Just keep following instructions and you'll get a working build soon enough :)

@verekia
Copy link
Owner

verekia commented Oct 31, 2016

Closing for now. If more people keep getting confused with the build not working at such intermediate states, I'll change the readme to make it clearer. If you're one of these people, please upvote @sgatlf's original comment!

@verekia verekia closed this as completed Oct 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants