'eslint' is not recognized as an internal

2019-03-13 20:28发布

问题:

I'm trying to install eslint & run it in vs code. I ran this command:

npm i -g eslint

and it seemed to work, but I keep keep getting a "'eslint' is not recognized as an internal or external command" error when I try & run eslint. What gives?

http://eslint.org/docs/user-guide/command-line-interface

http://eslint.org/docs/user-guide/getting-started

回答1:

The eslint module must not be installed into global.

instead, you should install eslint-cli module into global.

So, first install eslint-cli gloablly:

npm -g i eslint-cli

then in the project folder: install eslint locally

npm i eslint --save-dev

Then in the project folder you can run someting like: (on Windows)

eslint .\


回答2:

Well, if you are a Windows user and installing eslint-cli not working for you, try using:

node node_modules\eslint\bin\eslint.js --init

it solves my problem.