NPM和Eslint:这令人困惑,这正常吗?

时间:2018-10-25 23:19:08

标签: javascript node.js npm eslint

我是JS的新手,我正在尝试学习棉绒。因此,我正在关注一个教程,其中我们在lint文件中设置了package.json阶段。

它看起来像这样:"lint": "./node_modules/.bin/eslint ."

因此,在终端中,当我运行./node_modules/.bin/eslint .时,它会按预期报告所有错误和警告。

/Users/me/dev/webapps/templates/sample_node_project/index.js
  1:1   error    Expected 1 empty line after require statement not followed by another require  import/newline-after-import
  1:35  error    Missing semicolon                                                              semi
  5:27  error    Missing semicolon                                                              semi
  9:3   warning  Unexpected console statement                                                   no-console
  9:53  error    Missing semicolon                                                              semi

✖ 5 problems (4 errors, 1 warning)
  4 errors and 0 warnings potentially fixable with the `--fix` option.

但是当我运行npm run lint时,我得到的是:

/Users/me/dev/webapps/templates/sample_node_project/index.js
  1:1   error    Expected 1 empty line after require statement not followed by another require  import/newline-after-import
  1:35  error    Missing semicolon                                                              semi
  5:27  error    Missing semicolon                                                              semi
  9:3   warning  Unexpected console statement                                                   no-console
  9:53  error    Missing semicolon                                                              semi

✖ 5 problems (4 errors, 1 warning)
  4 errors and 0 warnings potentially fixable with the `--fix` option.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sample_node_project@1.0.0 lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sample_node_project@1.0.0 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/me/.npm/_logs/2018-10-25T23_15_56_180Z-debug.log

因此,这引发了额外的错误,使我认为我的nodenpm已损坏。另外,在本教程中,讲师正在运行yarn lint,而他似乎得到的额外错误块要少得多。

那正常吗?

1 个答案:

答案 0 :(得分:2)

Ico1将消除您看到的NPM错误。由于发生lint错误,ESLint为您提供了非零的退出代码。 NPM基本上说它由于掉毛错误而无法正确运行。是的,这很正常。