I have an npm script in my package.json set up just like the snippet below. When I run
./node_modules/.bin/eslint app
eslint runs exactly as I would expect it to. When I run
npm run eslint
eslint seems to run fine but I then get a nasty error at the bottom of the output. I've pasted the npm-debug.log file below. Any idea why this is happening and how I can fix it?
"scripts": {
"eslint": "eslint app"
0 info it worked if it ends with ok
1 verbose cli [ 'node', '/usr/local/bin/npm', 'run', 'eslint' ]
2 info using [email protected]
3 info using [email protected]
4 verbose node symlink /usr/local/bin/node
5 verbose run-script [ 'preeslint', 'eslint', 'posteslint' ]
6 info preeslint [email protected]
7 info eslint [email protected]
8 verbose unsafe-perm in lifecycle true
9 info [email protected] Failed to exec eslint script
10 verbose stack Error: [email protected] eslint: eslint app/
10 verbose stack Exit status 1
10 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:213:16)
10 verbose stack at EventEmitter.emit (events.js:110:17)
10 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
10 verbose stack at ChildProcess.emit (events.js:110:17)
10 verbose stack at maybeClose (child_process.js:1015:16)
10 verbose stack at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
11 verbose pkgid [email protected]
12 verbose cwd /Users/mhaas2/projects/prototypes/ccapp
13 error Darwin 14.3.0
14 error argv "node" "/usr/local/bin/npm" "run" "eslint"
15 error node v0.12.2
16 error npm v2.8.4
17 error code ELIFECYCLE
18 error [email protected] eslint: eslint app/
18 error Exit status 1
19 error Failed at the [email protected] eslint script 'eslint app/'.
19 error This is most likely a problem with the ccapp package,
19 error not with npm itself.
19 error Tell the author that this fails on your system:
19 error eslint app/
19 error You can get their info via:
19 error npm owner ls ccapp
19 error There is likely additional logging output above.
20 verbose exit [ 1, true ]
Do you have any eslint errors for the JavaScript files?
What you have pasted here is the text from your npm-debug
file. Look at the ouput on your console/cmd for truly whats going on.
I tried your scenario and what happens is that when eslint run ends with a exit code of 1 (that means you have eslint error(s) in your code) and then when npm tackles that error code then it throws an error because internal task returned an exit code 1.
It will for sure run fine if you don't have any eslint errors.
So to answer your questions, Yes its behaving as expected.
To echo what @gyandeeps said, npm always outputs a bunch of debug info when a command returns a non-zero exit code. If you have linting errors, eslint returns 1 as the exit code. You can verify by running the same ESLint command in your console directly and also try running another task through npm that returns a 1 as the exit code.
rafaelbiten, vivek3003, andyfaizan, pmogren, oziks, ivawzh, soosap, KurtWagner, ilyoff, bhague1281, and 49 more reacted with thumbs up emoji
sebastiancarlsson, soosap, albertovasquez, huarse, joaoreynolds, potato4d, jnields, OlegVo, eleanor-byhook, jasonhargrove, and 7 more reacted with hooray emoji
tugberkugurlu, tim-phillips, paulintrognon, and PEM-- reacted with confused emoji
eleanor-byhook, sulco, pechitook, jasonhargrove, agindre, yspychala, Danjavia, and ierhyna reacted with heart emoji
All reactions
Though that solves the npm error log, it's not recommendable since you might want to concat commands like linting and then bundling with browserify, and the second one will occur even if you have code to fix. To be honest it also bothers me the error logging in the console and I don't know a way to silent that, but forcing a 0
exiting code it's not a good idea.
@jeremenichelli I fully agree with you, there should be a method of silencing the eslint output based on e.g. environmental variable.*
*In my particular case I would like to be able to run eslint through a package.json script without throwing npm errors AND to be able to use the same script as a git pre-commit script to actually output corresponding value from eslint.