Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm install fails on node-gyp rebuild (using puppet) #115

Closed
glesperance opened this issue Jul 30, 2012 · 12 comments
Closed

npm install fails on node-gyp rebuild (using puppet) #115

glesperance opened this issue Jul 30, 2012 · 12 comments

Comments

@glesperance
Copy link

I'm currently trying to deploy my web app using a puppet script issuing the npm installcommand using my webapp's directory as the CWD.

All packages but those that depend on node-gyp install correctly.

The strange thing is that when I donpm install manually in my app's directory, everything seems to work correctly. Setting up the PATH or NODE_ENV environment variables does not help. This could be linked to an issue with permissions although the puppet script does run as root so there shouldn't be any problem there.

Is there anything node-gyp requires to run properly that I should double check? Could npm be somehow dropping the privileges and causing these errors?


Below are two logs of different packages that failed to build on two different attempts (the second attempt had the bcrypt dep removed out of package.json)

bcrypt@0.7.0

504 info postuninstall bcrypt@0.7.0
505 error bcrypt@0.7.0 install: `node-gyp rebuild`
505 error `sh "-c" "node-gyp rebuild"` failed with 1
506 error Failed at the bcrypt@0.7.0 install script.
506 error This is most likely a problem with the bcrypt package,
506 error not with npm itself.
506 error Tell the author that this fails on your system:
506 error     node-gyp rebuild
506 error You can get their info via:
506 error     npm owner ls bcrypt
506 error There is likely additional logging output above.
507 error System Linux 3.2.0-23-generic
508 error command "nodejs" "/usr/bin/npm" "install"
509 error cwd /usr/local/src/wavo.me
510 error node -v v0.8.4
511 error npm -v 1.1.45
512 error code ELIFECYCLE
513 verbose exit [ 1, true ]

node-proxy@0.6.0

5503 error node-proxy@0.6.0 install: `node-gyp configure build`
5503 error `sh "-c" "node-gyp configure build"` failed with 1
5504 error Failed at the node-proxy@0.6.0 install script.
5504 error This is most likely a problem with the node-proxy package,
5504 error not with npm itself.
5504 error Tell the author that this fails on your system:
5504 error     node-gyp configure build
5504 error You can get their info via:
5504 error     npm owner ls node-proxy
5504 error There is likely additional logging output above.
5505 error System Linux 3.2.0-23-generic
5506 error command "nodejs" "/usr/bin/npm" "install"
5507 error cwd /usr/local/src/wavo.me
5508 error node -v v0.8.4
5509 error npm -v 1.1.45
5510 error code ELIFECYCLE
5511 verbose exit [ 1, true ]
@TooTallNate
Copy link
Contributor

The npm-debug.log file doesn't output node-gyp's logs. This doesn't really tell me anything. Try npm install --verbose 2>&1 | grep gyp to give me just node-gyp's verbose output. Thanks!

@glesperance
Copy link
Author

Ok here's the output :

gyp ERR! configure error 
gyp ERR! stack Error: EACCES, stat '/root/.node-gyp/0.8.4'
gyp ERR! System Linux 3.2.0-23-generic
gyp ERR! command "node" "/usr/lib/nodejs/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /usr/local/src/wavo.me/node_modules/rocket/node_modules/now/node_modules/node-proxy
gyp ERR! node -v v0.8.4
gyp ERR! node-gyp -v v0.6.1
gyp ERR! not ok 

So this seems to be a permission issue. I managed to bypass the problem by doing

sudo -i sh -c "cd ${app_directory}; npm install"

instead of

npm install

The log files are themselves created by root, but it seems that there is indeed a privilege drop as the node_modules directory is owned by vagrant which is the base user I am using on my test system.

Any idea why this works when we reset the ENV params and not when we simply issue the npm install?

@lanhed
Copy link

lanhed commented Nov 23, 2012

I had a similar problem. Then I installed Homebrew (http://mxcl.github.com/homebrew/) and ran brew doctor that told me my ENV variables were in the wrong order. I created a .bash_profile in my home directory and copy pasted the variables in there starting with /usr/local/bin I then reinstalled (was installing duino) and BANG, it works!

@ianwestcott
Copy link

I have encountered a similar issue when using CFEngine to run npm install, as well as when using supervisor to start the node app for the first time. In both cases I get the following error:

gyp WARN EACCES user "root" does not have permission to access the dev dir /root/.node-gyp/0.10.5

In both cases I am attempting to run the commands as a user other than root, but CFEngine and/or supervisor are themselves running as root and are attempting to run the commands as the user outside of any kind of shell.

The only method I have found to work around this error (and allow my node app to install) is to manually set the HOME environment variable before running the install command. Only with the HOME variable set (in this case to the home directory of the user that the command should be run as) is node-gyp able to find the correct dev dir and complete the install.

At the very least, I would like to be able to configure a custom path to use as the dev dir for cases where the install is running outside of a shell or as an arbitrary user.

@clkao
Copy link

clkao commented Nov 14, 2013

I've been seeing this issue from time to time. finally got around to take a closer look. This is actually caused by npm setuid to SUDO_UID, so even the messages says user "root" does not have permission to access the dev dir /root/.node-gyp/xxx, the process is actually already setuid'ed. I believe this is probably npm trying to be smart for people using sudo without knowning what they are doing. env SUDO_UID= SUDO_USER= npm i fixes this

@JayBeavers
Copy link
Contributor

Feels related to #222.

@patrick-m-m
Copy link

I am running into the same issue using Chef and the kerberos module, a dependency of Mongoose and MongooseQ. It takes the specific flavor of infinitely logging to builderror.log:

gyp WARN EACCES attempting to reinstall using temporary dev dir "/root/tmp/.node-gyp"
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/tmp/.node-gyp/0.10.22"

I had asked a stackoverflow question about this before finding the builderror.log file and arriving at this issue number. Linking it for completeness, and it has a few more details if they'd help.

I will attempt your env variable fix, @clkao, but I would appreciate some insight on what exactly it does and if/when/how I should worry about unsetting those variables. I'm running on ubuntu and don't seem to have either the SUDO_UID or SUDO_USER variables set under normal circumstances. Many thanks.

@padawan
Copy link

padawan commented Jan 30, 2014

Adding --unsafe-perm to the nom install… line did the trick for me.

@RussNelson
Copy link

Yes, this is definitely related to #222. By my analysis, when npm is started sudo root, it decides that it should install into /root, but then when it downgrades the user pemission to run node-gyp, node-gyp can't create its ~/.node-gyp folder for building. If npm is going to downgrade, then it should install into the user's home folder.

@reilg
Copy link

reilg commented Dec 4, 2014

npm install node-inspector -g --unsafe-perm worked for me as well.

@a0viedo
Copy link
Member

a0viedo commented Mar 27, 2018

hey @glesperance, it's been long time. is this still an issue?

@glesperance
Copy link
Author

glesperance commented Mar 27, 2018

hey @a0viedo thanks for asking. I dont recall having this problem anymore. Not sure if we ever fixed it either; 6 years is quite some time ago haha.

Closing the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests