Node-gyp: Upon trying to install module as a privileged user (root) NPM gets stuck in a loop

Created on 25 Feb 2018  路  10Comments  路  Source: nodejs/node-gyp

  • Node Version:
    node 8.9.4 / npm 5.6.0
  • Platform:
    Linux apollo 4.4.0-87-generic #110-Ubuntu SMP Tue Jul 18 12:55:35 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  • Compiler:
Using built-in specs.
COLLECT_GCC=cc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.5' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5) 
  • Module:
    node-sass

Verbose output (from npm or node-gyp):

gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.9.4
gyp verb ensuring nodedir is created /var/www/test/node_modules/node-sass/.node-gyp/8.9.4
gyp WARN EACCES user "root" does not have permission to access the dev dir "/var/www/test/node_modules/node-sass/.node-gyp/8.9.4"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/var/www/test/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space
gyp verb command install [ '8.9.4' ]
gyp verb install input version string "8.9.4"
gyp verb install installing version: 8.9.4
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.9.4
gyp verb ensuring nodedir is created /var/www/test/node_modules/node-sass/.node-gyp/8.9.4
gyp WARN EACCES user "root" does not have permission to access the dev dir "/var/www/test/node_modules/node-sass/.node-gyp/8.9.4"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/var/www/test/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space
gyp verb command install [ '8.9.4' ]
gyp verb install input version string "8.9.4"
gyp verb install installing version: 8.9.4
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.9.4
gyp verb ensuring nodedir is created /var/www/test/node_modules/node-sass/.node-gyp/8.9.4
gyp WARN EACCES user "root" does not have permission to access the dev dir "/var/www/test/node_modules/node-sass/.node-gyp/8.9.4"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/var/www/test/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space
gyp verb command install [ '8.9.4' ]
gyp verb install input version string "8.9.4"
gyp verb install installing version: 8.9.4
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.9.4
gyp verb ensuring nodedir is created /var/www/test/node_modules/node-sass/.node-gyp/8.9.4
gyp WARN EACCES user "root" does not have permission to access the dev dir "/var/www/test/node_modules/node-sass/.node-gyp/8.9.4"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/var/www/test/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space
gyp verb command install [ '8.9.4' ]
gyp verb install input version string "8.9.4"
gyp verb install installing version: 8.9.4
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.9.4
gyp verb ensuring nodedir is created /var/www/test/node_modules/node-sass/.node-gyp/8.9.4
gyp WARN EACCES user "root" does not have permission to access the dev dir "/var/www/test/node_modules/node-sass/.node-gyp/8.9.4"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/var/www/test/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space
gyp verb command install [ '8.9.4' ]
gyp verb install input version string "8.9.4"
gyp verb install installing version: 8.9.4
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.9.4
gyp verb ensuring nodedir is created /var/www/test/node_modules/node-sass/.node-gyp/8.9.4
gyp WARN EACCES user "root" does not have permission to access the dev dir "/var/www/test/node_modules/node-sass/.node-gyp/8.9.4"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/var/www/test/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space
gyp verb command install [ '8.9.4' ]
gyp verb install input version string "8.9.4"
gyp verb install installing version: 8.9.4
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.9.4
gyp verb ensuring nodedir is created /var/www/test/node_modules/node-sass/.node-gyp/8.9.4
gyp WARN EACCES user "root" does not have permission to access the dev dir "/var/www/test/node_modules/node-sass/.node-gyp/8.9.4"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/var/www/test/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space
gyp verb command install [ '8.9.4' ]
gyp verb install input version string "8.9.4"


Upon trying to install node-sass as a privileged user (root) NPM gets stuck in a loop.

I'm not trying to install node-sass as a global package so this cannot apply: https://docs.npmjs.com/getting-started/fixing-npm-permissions.

screen
Screen share here.

Steps to reproduce

  • Make sure you are authenticated as a privileged user (root)
  • Run npm init --yes
  • Run npm install node-sass --save
Node Sass --> Dart Sass

Most helpful comment

Hey people, if this even can make any "profit" for you, I am mean if this is still relevant - in order to solve this issue with "root" user all you need to include in your command: sudo npm install *any package name here*-> just add the flag --unsafe-perm

This is well described here: https://github.com/nodejs/node-gyp/issues/454

All 10 comments

Thanks for the bug report. Good write-up. Can you check if #1384 fixes it?

Hi @bnoordhuis

I have the same problem. As the npm install configured as a part of the app build, most of our Jenkins jobs are knocked down. We can't manually install and try the steps.

it needs some serious fixing soon.

Thanks.

Well, did the PR work for you?

Nope, It didn't work for me.

@arocki7 Then it's probably not the same issue. Can you file a new bug report and post steps to reproduce and anything else that is relevant?

@bnoordhuis will do.

I also get that error on a clean ubuntu 17 (artful) install. Just setup Ubuntu, then install nodejs 8.10 LTS, then try to install sudo npm install -g @angular/cli or sudo npm install -g node-sass.

As a workaround I could npm install node-sass and then copy the node-sass and node-gyp from local node_modules to /usr/lib/node_modules.

I encountered the same issue yesterday trying to install posix (just as in the initial report, mkdir tmp; cd tmp; npm init --yes; npm install posix --save;). After finding this bug report and seeing that it was fixed, I tried upgrading the npm-bundled copy as per the Wiki. That, unfortunately, did not do anything, because npm actually bundles _two_ copies of node-gyp, the other one located under the npm-lifecycle module. So,

npm explore npm -g -- npm explore npm-lifecycle -- npm install npmjs/node-gyp

did the trick. (Can someone confirm that invocation makes sense? If yes, that might be a fine addition to the wiki page.)

No infinite loop happens anymore when I try to install the posix package now. However, the behavior of node-gyp is pretty nonsensical:

maxwell /root/tmp # npm install posix --save

> [email protected] install /root/tmp/node_modules/posix
> node-gyp rebuild

gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/8.10.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/root/tmp/node_modules/posix/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, stat '/root/tmp/node_modules/posix/.node-gyp/8.10.0'
gyp ERR! System Linux 4.4.0-116-generic
gyp ERR! command "/opt/node-v8.10.0-linux-x64/bin/node" "/opt/node-v8.10.0-linux-x64/lib/node_modules/npm/node_modules/npm-lifecycle/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /root/tmp/node_modules/posix
gyp ERR! node -v v8.10.0
gyp ERR! node-gyp -v v4.0.0
gyp ERR! not ok 
  • I'm pretty sure root does have permission to access these paths, but uid 500 does not. osenv.user() shows the value of an environment variable, not the name of process.geteuid() -- which, ironically, is what I wanted to be able to do using the posix package in the first place :laughing:
  • After the first EACCES, node-gyp tries to instead select a temporary directory -- for some reason, however, it gets what seems to be its working directory back from os.tmpdir() ...?

AFAICS, I can work around this by manually specifying /tmp/.node-gyp as the dev dir. However, the process then still does not have permission to write to the directories where the binaries should actually end up ... but I guess that is a problem (well, questionable design decision?) on the npm end. I'm not sure if there is anything that can be done in node-gyp at all (except the "root does not have permission" thing -- no idea about the tmpdir), so this bug is probably fixed alright, but the experience is far from satisfactory.

Edit: Aaaand just now I found out about --unsafe-perm, which solves all these issues. Maybe an info message in case of an EACCES when process.geteuid() == 500 might be prudent?

Hey people, if this even can make any "profit" for you, I am mean if this is still relevant - in order to solve this issue with "root" user all you need to include in your command: sudo npm install *any package name here*-> just add the flag --unsafe-perm

This is well described here: https://github.com/nodejs/node-gyp/issues/454

Hey people, if this even can make any "profit" for you, I am mean if this is still relevant - in order to solve this issue with "root" user all you need to include in your command: sudo npm install *any package name here*-> just add the flag --unsafe-perm

This is well described here: #454

@magnafilix thank you for this. You saved me so much time with this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Yamakaky picture Yamakaky  路  3Comments

kimown picture kimown  路  3Comments

adrianescat picture adrianescat  路  3Comments

Flimm picture Flimm  路  3Comments

gengjiawen picture gengjiawen  路  3Comments