【问题标题】:npm throwing an error at the end of the eslint reportnpm 在 eslint 报告末尾抛出错误
【发布时间】:2018-03-27 01:07:41
【问题描述】:

在我的 typescript 项目上运行 eslint 时遇到问题。我有以下 package.json,我在其中编写了一个脚本来运行 eslint:

{
  "name": "ts-tutorial",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "transpile": "tsc",
    "lint": "eslint src --ext ts"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "eslint": "^4.19.1",
    "eslint-config-standard": "^11.0.0",
    "eslint-plugin-import": "^2.9.0",
    "eslint-plugin-node": "^6.0.1",
    "eslint-plugin-promise": "^3.7.0",
    "eslint-plugin-standard": "^3.0.1",
    "typescript": "^2.7.2",
    "typescript-eslint-parser": "^14.0.0"
  }
}

所以现在,当我运行 npm run ling 时,我得到了正确的输出,其中包含我的代码所存在的所有错误,需要进行 linted。但在列表末尾,我看到一个 npm 错误:

✖ 7 problems (7 errors, 0 warnings)
  6 errors, 0 warnings potentially fixable with the `--fix` option.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ts-tutorial@1.0.0 lint: `eslint src --ext ts`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ts-tutorial@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!     /home/dbugger/.npm/_logs/2018-03-26T16_44_57_459Z-debug.log

是什么导致了这个错误?我已经阅读了日志文件,但我无法理解阅读它的问题。

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'lint' ]
2 info using npm@5.5.1
3 info using node@v8.9.3
4 verbose run-script [ 'prelint', 'lint', 'postlint' ]
5 info lifecycle ts-tutorial@1.0.0~prelint: ts-tutorial@1.0.0
6 info lifecycle ts-tutorial@1.0.0~lint: ts-tutorial@1.0.0
7 verbose lifecycle ts-tutorial@1.0.0~lint: unsafe-perm in lifecycle true
8 verbose lifecycle ts-tutorial@1.0.0~lint: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/home/dbugger/projects/exercises/ts-tutorial/node_modules/.bin:/home/dbugger/.rbenv/plugins/ruby-build/bin:/home/dbugger/.rbenv/shims:/home/dbugger/.rbenv/bin:/home/dbugger/npm-global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle ts-tutorial@1.0.0~lint: CWD: /home/dbugger/projects/exercises/ts-tutorial
10 silly lifecycle ts-tutorial@1.0.0~lint: Args: [ '-c', 'eslint src --ext ts' ]
11 silly lifecycle ts-tutorial@1.0.0~lint: Returned: code: 1  signal: null
12 info lifecycle ts-tutorial@1.0.0~lint: Failed to exec lint script
13 verbose stack Error: ts-tutorial@1.0.0 lint: `eslint src --ext ts`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:280:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid ts-tutorial@1.0.0
15 verbose cwd /home/dbugger/projects/exercises/ts-tutorial
16 verbose Linux 4.13.0-37-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "lint"
18 verbose node v8.9.3
19 verbose npm  v5.5.1
20 error code ELIFECYCLE
21 error errno 1
22 error ts-tutorial@1.0.0 lint: `eslint src --ext ts`
22 error Exit status 1
23 error Failed at the ts-tutorial@1.0.0 lint script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

【问题讨论】:

    标签: typescript eslint


    【解决方案1】:

    这是意料之中的。按照设计,如果有任何 linting 错误,eslint 会以状态 1 退出。 npm 将此解释为错误,它会告诉您。

    如果您想抑制错误的退出代码,可以使用此处建议的解决方法之一:https://github.com/eslint/eslint/issues/7933

    【讨论】:

    • 我绝对不会想到这一点。谢谢。
    • 很高兴这对您有帮助,@EnriqueMorenoTent。对于未来的读者,如果您可以将此标记为正确答案,那就太好了。
    • 因此,一个可能的“解决方案”是将脚本更改为:"lint": "eslint src --ext ts; exit 0"
    猜你喜欢
    • 2018-12-23
    • 2018-08-06
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多