Express.js + lint 给出错误

Express.js + lint gives mistake

https://www.youtube.com/watch?v=Fa4cRMaTDUI 我正在看这节课,并试图重现作者所做的一切。在 19:00,他设置了 vue.js-express.js 项目。他创建了名为 'server' 的文件夹。在 'server/' 他跑 'npm init -f'。然后'npm install --save nodemon eslint',然后他就init了eslint。 然后在 package.json 文件中他写道:

"scripts": {
    "start": "nodemon src/app.js --exec 'npm run lint && node'",
    "lint": "eslint **/*.js"
}

然后在文件夹 'server' 中创建文件夹 'src'。在 'src' 中,他创建了 'app.js'。在'app.js;有一个简单的 console.log('hello')。 然后他跑'npm start'。 'Hello' 打印在终端中,nodemon 和 eslint 工作正常。然后他输入 'npm install --save express'。那就是我的问题开始的地方。安装 express.js 后,我输入 'npm start' 并在终端中收到此错误:

Oops! Something went wrong! :(

ESLint: 5.0.0.
No files matching the pattern "node_modules/ipaddr.js" were found.
Please check for typing mistakes in the pattern.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! server@1.0.0 lint: `eslint **/*.js`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the server@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/r/.npm/_logs/2018-06-25T10_32_02_027Z-debug.log
[nodemon] process failed, unhandled exit code (2)
[nodemon] Error
at Bus.utils.bus.on (/home/r/projects/tab-tracker/server/node_modules    /nodemon/lib/nodemon.js:148:25)
    at Bus.emit (events.js:164:20)
at ChildProcess.<anonymous> (/home/r/projects/tab-tracker/server/node_modules/nodemon/lib/monitor/run.js:164:11)
at ChildProcess.emit (events.js:159:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)

为什么会这样?

@joknawe 在评论中给出了正确答案,谢谢。 编辑:

Looks like maybe it is trying to lint your node_modules directory. This should be ignored by default, but your wildcard **/*.js may be causing the issue. Try just using eslint

在 Mac 中我修复了它,只是更改了以下行

上一个

"lint": ""lint": "./node_modules/.bin/eslint **/*.js""

之后

"lint": "./node_modules/.bin/eslint src/*.js"

引用该模式,它与以前版本的 eslint 一样工作正常

"lint": "eslint \"**/*.js\""

致谢 https://github.com/eslint/eslint/issues/10599

替换您的代码

"start": "nodemon src/app.js --exec 'npm run lint && node'",
"lint": "eslint **/*.js"

为了

"start": "nodemon src/app.js --exec 'npm run lint && node'",
"lint": "eslint"

我使用 WSL 并通过更改以下行修复。

上一个

"start": "./node_modules/nodemon/bin/nodemon.js src/app.js --exec 'npm run lint && node'",
"lint": "./node_modules/.bin/eslint **/*.js"

之后

"start": "./node_modules/nodemon/bin/nodemon.js src/app.js --exec 'npm run lint && node'",
"lint": "./node_modules/.bin/eslint src/**/*.js --fix"

只需在通配符周围添加引号 **/*.js

"scripts": {
    "start": "nodemon src/app.js --exec 'npm run lint && node'",
    "lint": "eslint **/*.js"
}

在 .eslint.js 文件中,您应该替换此代码

之前

"browser": true

之后

"node": true