我正在将我的环境设置为lint ES6.我安装了eslint,可以在我的node_modules中看到它.在我的node_modules / bin目录中,我有命令eslint.
我可以运行命令并将其指向目录,我没有错误:
./node_modules/.bin/eslint src / main / webapp / js / lcrf
我可以看到我需要修复的所有掉毛错误.
我还将命令添加到我的package.json中:
"scripts": { "lint": "eslint src/main/webapp/js/lcrf" },
现在我尝试用npm run lint运行命令.它会丢失我的文件并获得相同数量的linting错误,但随后出现节点错误.这是我的堆栈跟踪:
npm ERR! Darwin 14.3.0 npm ERR! argv "node" "/usr/local/bin/npm" "run" "lint" npm ERR! node v0.12.2 npm ERR! npm v2.7.4 npm ERR! code ELIFECYCLE npm ERR! lcrf@0.0.0 lint: `eslint src/main/webapp/js/lcrf` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the lcrf@0.0.0 lint script 'eslint src/main/webapp/js/lcrf'. npm ERR! This is most likely a problem with the lcrf package,npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! eslint src/main/webapp/js/lcrf npm ERR! You can get their info via: npm ERR! npm owner ls lcrf npm ERR! There is likely additional logging output above.
什么会导致这种情况发生?我运行命令的两种方式有什么区别?
解决方法
npm对来自eslint的非零返回代码感到害怕.如果你想让lint错误表明“哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇
如果您不使用退出代码(例如,停止后续构建步骤)并且您只希望输出只是eslint输出并且后续npm没有消失,请在package.json中使用它:
"lint": "eslint src/main/webapp/js/lcrf || exit 0"
请注意07000:
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.