Express.js + lint gives mistake

2020-07-10 10:28发布

问题:

https://www.youtube.com/watch?v=Fa4cRMaTDUI I am watching this lesson and trying to recreate everything author does. At 19:00 he sets vue.js-express.js project. He creates folder called 'server'. In 'server/' he runs 'npm init -f'. Then 'npm install --save nodemon eslint', then he inits eslint. Then in package.json file he writes:

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

Then in folder 'server' he creates folder 'src'. In 'src' he creates 'app.js'. And in 'app.js; there is a simple console.log('hello'). Then he runs 'npm start'. 'Hello' is printed in terminal, nodemon and eslint works just fine. Then he types 'npm install --save express'. Thats where my problem begins. After installing express.js i type 'npm start' and i get this error in terminal:

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)

Why is this happening?

回答1:

Quote the pattern and it works fine as in previous versions of eslint

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

Credit goes to https://github.com/eslint/eslint/issues/10599



回答2:

@joknawe in comments gave right answer, thanks. edit:

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



回答3:

I use WSL and i fixed by changing following line.

Previous

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

After

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


回答4:

In a Mac I fixed it just changing the following line

Previous

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

After

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



回答5:

Replace your code

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

for

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


回答6:

Just add quotes around the wildcard **/*.js.

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


回答7:

in .eslint.js file you should replace this code

Before

"browser": true

After

"node": true