node-gyp: User "undefined"/"nobody" does not have permission to access the dir

I’m not sure if this is a problem with a newer version of Node or this package.

This is using Docker, with image FROM node:8.1

I’m trying to globally install the spectacle-docs package npm install -g spectacle-docs. It attempts to use node-gyp at one point and cannot create a directory with user “undefined”, so it tries to use a local temp directory and then has an error about user “nobody”, and ends up going into an infinite loop trying to rebuild.

I’ve tried deleting the directory and re-doing install numerous times, no luck.

Output:

> node-sass@4.5.3 postinstall /usr/local/lib/node_modules/spectacle-docs/node_modules/node-sass
> node scripts/build.js

Building: /usr/local/bin/node /usr/local/lib/node_modules/spectacle-docs/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [ '/usr/local/bin/node',
gyp verb cli   '/usr/local/lib/node_modules/spectacle-docs/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library=' ]
gyp info using node-gyp@3.6.2
gyp info using node@8.1.2 | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` succeeded python2 /usr/bin/python2
gyp verb check python version `/usr/bin/python2 -c "import platform; print(platform.python_version());"` returned: "2.7.9\n"
gyp verb get node dir no --target version specified, falling back to host node version: 8.1.2
gyp verb command install [ '8.1.2' ]
gyp verb install input version string "8.1.2"
gyp verb install installing version: 8.1.2
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp WARN EACCES user "undefined" does not have permission to access the dev dir "/root/.node-gyp/8.1.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/spectacle-docs/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.1.2' ]
gyp verb install input version string "8.1.2"
gyp verb install installing version: 8.1.2
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.1.2
gyp verb ensuring nodedir is created /usr/local/lib/node_modules/spectacle-docs/node_modules/node-sass/.node-gyp/8.1.2
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/spectacle-docs/node_modules/node-sass/.node-gyp/8.1.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/spectacle-docs/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.1.2' ]
gyp verb install input version string "8.1.2"
gyp verb install installing version: 8.1.2
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.1.2
gyp verb ensuring nodedir is created /usr/local/lib/node_modules/spectacle-docs/node_modules/node-sass/.node-gyp/8.1.2
(This will loop forever)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 21
  • Comments: 20 (2 by maintainers)

Commits related to this issue

Most upvoted comments

You could add --unsafe to your npm install command. npm install -g your-package --unsafe

Found it via https://github.com/npm/npm/issues/1259

npm_config_user=root npm install -g ...

works for me

npm_config_user=root npm install -g ...

works for me

I added “npm config set user root” before npm install

@bnoordhuis Indeed, I understand now that it doesn’t seem to be a problem with node-gyp. But I already had set the USER to either node or root, and didn’t work.

However, I was able to get it working by changing the default npm-global directory.

@kingjerod maybe it will work for you as well:

USER node

RUN mkdir /home/node/.npm-global
ENV PATH=/home/node/.npm-global/bin:$PATH
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global

@phani1kumar add --unsafe solved the warning, thanks!

Installing Angular 4 CLI on macOS: for some reason root user can’t create hidden folders, folder names beginning with ‘.’. So cd to “/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/” in the command-line shell and do a “mkdir .node-gy.” Re-run “sudo npm install -g @angular/cli.” Install will finish.

As simple user try sudo npm install -g package instead of running it as root. It works for me.

@gabrielaraujof solution worked for me as well, it’s also an officially recommended way to solve permission errors. npm guide I haven’t seen any actual problems when sudo install, but they recommend not to, so, I guess this is the best possible solution.

Dockerfile I used

FROM node:9.6.1 as node-angular-cli

USER node
RUN mkdir /home/node/.npm-global
ENV PATH=/home/node/.npm-global/bin:$PATH
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
RUN npm install -g @angular/cli

@gibfahn actually I don’t remember, but what I’ve been using successfully so far is this:

FROM node:8.1.4

USER node

RUN mkdir /home/node/.npm-global ; \
    mkdir -p /home/node/app ; \
    chown -R node:node /home/node/app ; \
    chown -R node:node /home/node/.npm-global
ENV PATH=/home/node/.npm-global/bin:$PATH
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global

WORKDIR /home/node/app
RUN npm install

Both seem to be issues with node-sass’s post-install scripts + insufficient permissions. You could try npm install --unsafe-perms (read up on what it does) but either way, I don’t see anything that indicates a node-gyp bug.

The ‘user “undefined”’ warning is because the USER environment variable isn’t set.

Switched to yarn instead of NPM and it fixed my particular issue.