Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

npm postinstall "npm WARN cannot run in wd" #3497

Closed
mattheworiordan opened this issue May 29, 2013 · 8 comments
Closed

npm postinstall "npm WARN cannot run in wd" #3497

mattheworiordan opened this issue May 29, 2013 · 8 comments
Labels

Comments

@mattheworiordan
Copy link

Using: npm v1.2.14 & node v0.8.22

I have a simple package.json file with the following postinstall script:

..
"scripts": {
  "postinstall": "./node_modules/.bin/grunt build"
},
..

However, every time I run sudo npm install on my local OS X machine, I get the following error: npm WARN cannot run in wd myapp@3.2.33 sudo ./node_modules/.bin/grunt build (wd=/folder)

I have tried changing the actual postinstall script to run grunt at different paths, and even just set it to "echo postinstall" and it still fails.

Why is NPM not allowing that postinstall script to work? What does wd mean in this context?

Thanks.

@mbilker
Copy link

mbilker commented May 31, 2013

I believe 'wd' means working directory. NPM tries to downgrade its privileges when it runs scripts. That downgrading the privileges causes this error.

@mfncooper
Copy link
Contributor

As @mbilker mentioned, wd is the working directory. From the text you posted, it looks like your sudo user doesn't have write access to /folder.

@mattheworiordan
Copy link
Author

It seems that the problem I had was really down to the fact that I was using nvm and npm with a sudo user, where I really should have been using my user account. I reinstalled nvm for my user account without sudo, and this problem went away. Thanks for the help.

@springmeyer
Copy link

also hit this on Ubuntu running as root user. npm install --unsafe-perm worked around the problem, but I now know to stop running as root in general.

@luk-
Copy link
Contributor

luk- commented Sep 6, 2013

Keep in mind that running with unsafe-perm will run npm lifecycle scripts as your user instead of nobody, and is a potential security risk.

@gerisztein
Copy link

or you can use an external file called .npmrc with just the following content:

unsafe-perm = true

@dkoleary88
Copy link
Contributor

I fixed this by changing the ownership of /usr/local and ~/Users/user-name like so:

sudo chown -R my_name /usr/local

This allowed me to do everything without sudo

NiGhTTraX added a commit to NiGhTTraX/react-test-buffet that referenced this issue Feb 5, 2017
by running `npm install` as root. See npm/npm#3497.
euank added a commit to wobscale/EuIrcBot that referenced this issue Feb 15, 2017
This is required nowadays because at some point npm decided root users
shouldn't be allowed to run install scripts.

See also npm/npm#3497
hoverduck added a commit to Automattic/wp-e2e-tests that referenced this issue Apr 11, 2017
hoverduck added a commit to Automattic/wp-e2e-tests that referenced this issue Apr 13, 2017
hoverduck added a commit to Automattic/wp-e2e-tests that referenced this issue Apr 19, 2017
randytsmith added a commit to randytsmith/javascript_testing that referenced this issue Apr 1, 2018
by running `npm install` as root. See npm/npm#3497.
Liu233w pushed a commit to Liu233w/acm-statistics that referenced this issue Apr 25, 2018
这样的话,使用 root 权限运行 postinstall 脚本就不会报错了(安全原因)

see npm/npm#3497
SamHwang1990/blog#5
dezine2dev added a commit to dezine2dev/Javascript-testing that referenced this issue Jul 4, 2018
by running `npm install` as root. See npm/npm#3497.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

9 participants