npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

EACCESS error. How can avoid this without using sudo? I've heard I should never use sudo with npm.

Below is the command I ran with the error i recieved. Any Idea how I can get past this without using sudo? Thanks

MacBook-Pro% npm i react-spinners
Unhandled rejection Error: EACCES: permission denied, mkdir '/Users/isaacr./.npm/_cacache/index-v5/74/43’eactjs-strapi-m

npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/isaacr./.npm/_logs/2019-10-12T21_32_33_258Z-debug.log

Your issue is a known problem with file ownership being broken by past uses of sudo with global installs. This was fixed in: Release: 6.10.2

The quick fix is:

sudo chown -R $USER ~/.npm

If you are able to update npm to avoid the problem happening again, upgrade npm and then run the chown again one last time to fix any issues from the upgrade itself.

For global package installs, to avoid the need for sudo you can either take ownership of the target directories, or change the global install location to somewhere you control (usually a folder in your home folder). You can explicitly set the npm global location, or if you are using a node version manager which is installing node and npm to your home folder then implicitly the npm global packages are installed there too.

Thank you for the reply! I ended up using these two commands consecutively:
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
It seems as though I am in the clear, If not please do tell.

Thanks again for the reply