When I try to install something (gulp, sass, webpack, etc.) globally with sudo npm install packagename -g
I always get these errors:
node-pre-gyp WARN Hit error EACCES: permission denied, mkdir '/usr/local/lib/node_modules/webpack/node_modules/fsevents/lib'
gyp WARN EACCES user "root" does not have permission to access the dev dir "/Users/erik/.node-gyp/11.11.0"
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/webpack/node_modules/fsevents/.node-gyp'
And a whole lot more similar errors.
I have tried fixing disk permissions with Disk Repair. I have completely uninstalled and reinstalled Node. I have tried other answers on stack overflow, such as:
sudo chown -R $(whoami) ~/.npm
and
sudo chown -R $(whoami) /usr/local/lib/node_modules
but this has not helped.
How do I fix the permissions so that I can install global npm packages again?
I'm running OS X Mojave with Node 11.11.0
I struggled with this a bit as well and eventually found that you need to set the global package installation location to a folder that you have permissions for.
npm config set prefix '~/.npm-global'
then export the path
export PATH=~/.npm-global/bin:$PATH
all this information can be found on the npm documentation site
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally