Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm run cmd fails while cmd on command line works

In my HTTP Status Check project:

If I run node_modules/.bin/jshint . I get:

$ node_modules/.bin/jshint .
test/inAdapters_fileAdapter.js: line 73, col 31, Missing semicolon.

1 error

It executes correctly and produces the expected output: 1 error.

But if I add that command to package.json and try and run it through npm run then it works and produces the expected output but also follows that with a bunch of errors:

$ npm run jshint

> [email protected] jshint /home/guy/source/http-status-check
> jshint .

test/inAdapters_fileAdapter.js: line 73, col 31, Missing semicolon.

1 error

npm ERR! Linux 3.13.0-24-generic
npm ERR! argv "node" "/home/guy/local/bin/npm" "run" "jshint"
npm ERR! node v0.10.31
npm ERR! npm  v2.0.0
npm ERR! code ELIFECYCLE
npm ERR! [email protected] jshint: `jshint .`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] jshint script.
npm ERR! This is most likely a problem with the http-status-check package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     jshint .
npm ERR! You can get their info via:
npm ERR!     npm owner ls http-status-check
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/guy/source/http-status-check/npm-debug.log

This is how it's defined in package.json:

  "scripts": {
    "jshint": "node_modules/.bin/jshint .",
  },

What have I done wrong?

like image 330
Guy Avatar asked Sep 28 '14 19:09

Guy


People also ask

Why npm command is not working on CMD?

The error “npm is not recognized as an internal or external command” error may occur because either the npm is not installed or it is not added to the windows path. To resolve this error, the first solution is to install Node. js on Windows as Node. js is equipped with npm by default.

What does the npm Run command do?

npm run sets the NODE environment variable to the node executable with which npm is executed. If you try to run a script without having a node_modules directory and it fails, you will be given a warning to run npm install , just in case you've forgotten.


1 Answers

Don't exit with a non-zero error code unless you really mean it. Except for uninstall scripts, this will cause the npm action to fail, and potentially be rolled back. If the failure is minor or only will prevent some optional features, then it's better to just print a warning and exit successfully.

From https://www.npmjs.org/doc/misc/npm-scripts.html

Use:

node_modules/.bin/jshint .; true

Or write a wrapper that calls jshint and then ignores the exit code and exits successfully with a exit code of zero.

like image 115
Dan D. Avatar answered Oct 06 '22 01:10

Dan D.