How to Fix: npm WARN cannot run in wd

You may encounter this issue when you run npm with root permission.

In my case, I created a postinstall command to fix a particular node module’s problem:

If works good on my local Mac, but failed on my server, during the build process, it failed to run the postinstall command:

The problem is caused by that npm uses an incorrect privilege to invoke the command(see npm documentation):

If npm was invoked with root privileges, then it will change the uid to the user account or uid specified by the user config, which defaults to nobody. Set the unsafe-perm flag to run scripts with root privileges.

The solution is simple:

BTW, the method below does not work in this case (see this issue):

References:

Leave a Comment

Your email address will not be published. Required fields are marked *