How to fix Npm install failed with "cannot run in wd"

I was trying to upgrade my blogs ghost version to 0.9(which btw has some cool features) and I stumbled upon an issue when trying to upgrade the packages.

Every time I run

sudo npm install --production  

on my server, I get the following error:

npm WARN cannot run in wd ghost@0.9.0 node core/server/utils/npm/preinstall.js (wd=/var/www/ghost)  

On digging a bit deep, I found that NPM tries to downgrade its privileges when it runs scripts. That downgrading the privileges causes this error.

TL;DR:

So the workarounds are:
1. Run sudo npm run postinstall manually. OR
2. Run npm install --unsafe-perm OR
3. Run sudo chown -R my_name /usr/local

References:
1.Fixing npm permissions
2.User

comments powered by Disqus