''eslint' is not recognized as an internal or external command

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 getting an error when I try to run eslint :

"'eslint' is not recognized as an internal or external command, operable program or batch file".

What gives?

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

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



Solution 1:[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 .\

Solution 2:[2]

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

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

Or, you can use npx which lets you run local commands in node_modules/.bin :

npx eslint --help

For yarn use :

yarn eslint --help

Note:

  1. This answer is updated to include yarn and npx.
  2. This issue is related to modules installed locally.

Solution 3:[3]

Solution posted works for me: Step 1: eslint install globally npm -g i eslint-cli

Step 2: eslint install locally npm i eslint --save-dev

adding 2 more step: Step 3: eslint --init

It ask various questions e.g. ? How would you like to use ESLint? · style ? What type of modules does your project use? · none ? Which framework does your project use? · none ? Does your project use TypeScript? · No / Yes ? Where does your code run? · browser ? How would you like to define a style for your project? · prompt ? What format do you want your config file to be in? · JavaScript ? What style of indentation do you use? · tab ? What quotes do you use for strings? · single ? What line endings do you use? · unix ? Do you require semicolons? · No / Yes

Answer them based on your need.

Step 4: eslint yourfile.js This will show errors/warnings with your file. This way linting process is completed for js file.

Solution 4:[4]

I have got the same error :

I have solved this issue by using below command :

  • npm -g i eslint-cli
  • npm i eslint-plugin-promise@latest --save-dev

Solution 5:[5]

For Windows users

Add this to your Environment Path: "%AppData%\npm"

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Felix
Solution 2 Henke
Solution 3 Avneet
Solution 4
Solution 5 Adedoyin Akande