Home > Back-end >  "zsh: command not found: eslint" (and other commands installed via npm)
"zsh: command not found: eslint" (and other commands installed via npm)

Time:09-14

I just reset my Macbook and am getting "command not found" after installing apps via npm.

I have a working install of npm and node on my machine:

$ node -v
v18.9.0

$ npm -v
8.19.1

I've used npm install within my project directory, and can see the node_modules folder with the associated commands.

However, when I run something like eslint, I get:

$ eslint 
zsh: command not found: eslint

My path is up-to-date:

$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

I'm assuming that my machine isn't able to find the installed apps, but I don't know how to fix this.

CodePudding user response:

For eslint to be recognized as a command, you need to have it in the PATH and one way to do this is to install the package globally. Which means that running the command will run the package installed globally and not the local one.

If you want to use the package from your local node_modules folder, you need to run it with npx eslint. You could also define an alias in the package.json to run it with npm run eslint.

One last possible solution would be to add the path node_modules/.bin to your PATH.

CodePudding user response:

In project folder run:

./node_modules/.bin/eslint --init

For more information.

  • Related