在命令行上运行cmd时,npm运行cmd失败

在我的HTTP状态检查项目中 :

如果我运行node_modules/.bin/jshint . 我得到:

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

它正确执行并产生预期的输出:1错误。

但是,如果我将这个命令添加到package.json中,并尝试通过npm run那么它将起作用并产生预期的输出,但是也会出现一些错误:

 $ npm run jshint > http-status-check@0.0.5 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! http-status-check@0.0.5 jshint: `jshint .` npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the http-status-check@0.0.5 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 

这是它在package.json中的定义:

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

我做错了什么?

除非你确实是这个意思,否则不要用非零的错误代码退出。 除了卸载脚本之外,这将导致npm操作失败,并可能被回滚。 如果失败是轻微的,或者只会阻止某些可选function,那么最好只打印一个警告并成功退出。

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

使用:

 node_modules/.bin/jshint .; true 

或者编写一个调用jshint的包装器,然后忽略退出代码,并退出代码为零的成功退出。

Interesting Posts