27

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

Khalid Hussain
  • 1,675
  • 17
  • 25
wqu
  • 455
  • 1
  • 4
  • 8
  • 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. – Qix - MONICA WAS MISTREATED Sep 23 '18 at 07:17

8 Answers8

30

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

./node_modules/.bin/eslint --init
Nelu
  • 16,644
  • 10
  • 80
  • 88
24

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.

Community
  • 1
  • 1
rajatppn
  • 440
  • 2
  • 7
  • 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 – wqu Apr 26 '16 at 20:44
  • 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 – wqu Apr 26 '16 at 22:47
  • Do you know how to use a terminal editor like vi or nano? If not what editor do you use? – rajatppn Apr 27 '16 at 05:52
  • 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 – wqu Apr 30 '16 at 03:43
6

Try

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

Let me know if you face any issues.

Anjum....
  • 4,086
  • 1
  • 35
  • 45
Raja Sekar
  • 2,062
  • 16
  • 23
  • 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 – wqu Apr 26 '16 at 20:41
  • 6
    you have to run it from your project folder /node_modules/.bin/eslint --init. This is safe when compared to other methods. – Raja Sekar Apr 27 '16 at 06:40
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
1

You can install eslint inside your directory and run this command

npm init @eslint/config
bkmalan
  • 174
  • 1
  • 3
0

For: Zsh: command not found: eslint

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

then run:

npm install -g eslint

It should work

Antonio
  • 1
  • 1
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

-1

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