在命令行上运行cmd时,npm run cmd失败 [英] npm run cmd fails while cmd on command line works

查看:196
本文介绍了在命令行上运行cmd时,npm run cmd失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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

但是,如果我将该命令添加到package.json并尝试通过npm run运行它,则它可以正常工作并产生预期的输出,但也会导致一系列错误:

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

> 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中定义的方式:

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

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

我做错了什么?

推荐答案

除非您是真的意思,否则请不要退出非零错误代码.除卸载脚本外,这将导致npm操作失败,并有可能被回滚.如果故障很小,或者只会阻止某些可选功能,那么最好打印警告并成功退出.

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.

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

使用:

node_modules/.bin/jshint .; true

或者编写一个包装,该包装调用jshint,然后忽略退出代码,并以零退出代码成功退出.

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

这篇关于在命令行上运行cmd时,npm run cmd失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆