32

I get the following error installing eslint:

npm ERR! Darwin 15.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "eslint"
npm ERR! node v5.5.0
npm ERR! npm  v3.8.8
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access

npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/Leviathan/lj/npm-debug.log

I have not been able to figure out how to install eslint and also get this line:

eslint --init to run to create the .eslintrc file

1
  • 1
    For what it's worth, it's almost never a good idea to install ESLint globally - running scripts directly from package.json includes node_modules/.bin in your PATH automatically. Also, avoid running sudo when you can - change or loosen permissions if needed. /usr/local/ should be pretty liberal in who can read/write things within it, in particular. Commented Sep 23, 2018 at 7:17

9 Answers 9

34

If you're getting eslint: command not found try:

./node_modules/.bin/eslint --init
Sign up to request clarification or add additional context in comments.

1 Comment

Great answer for if you don't want to install it globally!
26

It looks like you're trying to install globally while your user doesn't have access to the global node_modules folder. You can try installing it as root or chown '/usr/local/lib/node_modules'.

Install as root -

    sudo npm install -g eslint

Chown -

    chown user:group /usr/local/lib/node_modules
    npm install -g eslint

You can also change permissions to /usr/local/lib/node_modules to allow your user access using chmod.

Edit: Try the solution in the answer here "Permission Denied" when trying to install ESlint on OSX globally

Add this to ~/.npmrc:

prefix = ${HOME}/.npm-packages https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md You also have to add ${HOME}/.npm-packages/.bin to your PATH so that your shell knows where to look up the globally installed scripts.

4 Comments

I still get the same errors for the first command, and cant run eslint --init afterwards, for the chown... line when i enter it in it in the terminal i get: chown: user: illegal user name if i put my username instead of chown i still get the same error with: -bash: username: command not found
I am new to using the terminal, so the suggestions in your link and reply are sort of confusing, so what should i enter line by line in the terminal, as I keep getting -bash permission denied, command not found, or no such file or directory when trying those suggestions
Do you know how to use a terminal editor like vi or nano? If not what editor do you use?
I was able to get it to work by installing as root as you said. Strangely, i tried this before from a blog post online, but now it works for some reason? maybe the server was down
6

Try

npm install eslint --save-dev and then eslint --init.

Let me know if you face any issues.

2 Comments

I get a few warnings and I also get this: UNMET PEER DEPENDENCY grunt@~0.4.0 and when i try to run eslint --init it says: -bash: eslint: command not found
you have to run it from your project folder /node_modules/.bin/eslint --init. This is safe when compared to other methods.
1

May be updating the dependencies to their latest versions (including major version changes) in the package.json file. would save you time.

npx npm-check-updates -u

or you may have to install eslint globally.

npm i eslint -g

and after removing node modules of your current project

eslint --init

Comments

1

You can install eslint inside your directory and run this command

npm init @eslint/config

Comments

0

For: Zsh: command not found: eslint

npm install eslint-plugin-react-hooks --save --dev

then run:

npm install -g eslint

It should work

Comments

0

Run a general update to upgrade all outdated packages run npm outdated to see updated packages then run npm update also npm-check-updates and npm install to finish up and your bug might be fixed

Comments

0

If you are trouble in powershell you may need execute before using cli cmds:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

After installed cli commands may start to work! Question was not OS related but it also a solution for windows users.

Comments

-1

eslint --init to run to create the .eslintrc file is says create .eslintrc, you probably forgot to include . before eslintrc

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.