1
votes

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

1
For me, i just wanted to make it work an addet the --unsafe-perm option, for example when installing sqlite3 sudo npm install --unsafe-perm -g sqlite3. Then it worked, but I don't know the underlying problem.Roland Starke
Thanks! That actually worked. Still not sure why I get so many errors when installing globally.Kokodoko

1 Answers

3
votes

A rule of thumb, as I have learned is to never use npm install with sudo! This created items with root as owner as opposed to you as owner.