The documentation says (also here):
If npm was invoked with root privileges, then it will change the uid to the user account or uid specified by the
userconfig, which defaults tonobody. Set theunsafe-permflag to run scripts with root privileges.
Your options are:
-
Run
npm installwith the--unsafe-permflag:[sudo] npm install --unsafe-perm -
Add the
unsafe-permflag to yourpackage.json:"config": { "unsafe-perm":true } -
Don’t use the
preinstallscript to install global modules, install them separately and then run the regularnpm installwithout root privileges:sudo npm install -g coffee-script node-gyp npm install
Related:
- package.json for global module installation