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

User "undefined"/"nobody" does not have permission to access the dir #1236

Closed
kingjerod opened this issue Jun 16, 2017 · 20 comments
Closed

User "undefined"/"nobody" does not have permission to access the dir #1236

kingjerod opened this issue Jun 16, 2017 · 20 comments

Comments

@kingjerod
Copy link

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)
@gabrielaraujof
Copy link

gabrielaraujof commented Jun 18, 2017

Same with me. I'm trying to build a docker image with a global install of the firebase-tools, which ends up needing the node-gyp.

I'm building the same image for two versions of node: 6.x (LTS ) and v8.x (latest). Locally, both images build fine, but when I try to build in docker hub only the v6.x builds successfully. With the v8.x it gets trapped in the access permissions for undefined and nobody user. I'm already using the root user (USER root), since without this setting (or using USER node) both images fail to build.

This is the Dockerfile:

FROM node:latest
USER root

RUN npm install --quiet --no-progress -g @angular/cli@latest firebase-tools
RUN npm cache clean --force

And this is part of the output:

Step 4/5 : RUN npm install --quiet --no-progress -g @angular/cli@latest firebase-tools

 ---> Running in fce3da11b04e
 
 npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
 /usr/local/bin/firebase -> /usr/local/lib/node_modules/firebase-tools/bin/firebase
 /usr/local/bin/ng -> /usr/local/lib/node_modules/@angular/cli/bin/ng

> node-sass@4.5.3 install /usr/local/lib/node_modules/@angular/cli/node_modules/node-sass
> node scripts/install.js

Unable to save binary /usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/vendor'
  at Object.fs.mkdirSync (fs.js:890:18)
  at sync (/usr/local/lib/node_modules/@angular/cli/node_modules/mkdirp/index.js:71:13)
  at Function.sync (/usr/local/lib/node_modules/@angular/cli/node_modules/mkdirp/index.js:77:24)
  at checkAndDownloadBinary (/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/scripts/install.js:111:11)
  at Object.<anonymous> (/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/scripts/install.js:154:1)
  at Module._compile (module.js:569:30)
  at Object.Module._extensions..js (module.js:580:10)
  at Module.load (module.js:503:32)
  at tryModuleLoad (module.js:466:12)
  at Function.Module._load (module.js:458:3)

errno: -13,
code: 'EACCES',
syscall: 'mkdir',
path: '/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/vendor' }

> grpc@1.3.8 install /usr/local/lib/node_modules/firebase-tools/node_modules/grpc > node-pre-gyp install --fallback-to-build --library=static_library
node-pre-gyp ERR! Tried to download(undefined): https://storage.googleapis.com/grpc-precompiled-binaries/node/grpc/v1.3.8/node-v57-linux-x64.tar.gz node-pre-gyp ERR! Pre-built binaries not found for grpc@1.3.8 and node@8.1.2 (node-v57 ABI) (falling back to source compile with node-gyp)
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/firebase-tools/node_modules/grpc/.node-gyp"
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp"
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp"
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp"
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp"
(infinite loop)

@bnoordhuis
Copy link
Member

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.

@gabrielaraujof
Copy link

@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

@julianonunes
Copy link

Doing what @gabrielaraujof suggested I could not create /var/www to copy my app files to. Tried to chmod and chown without success. Any suggestion?

@BoiseBaked
Copy link

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.

@tknecht
Copy link

tknecht commented Aug 22, 2017

@gabrielaraujof fix does not work for me.
https://gist.github.com/tknecht/33f584671eb8aaf19adb10aeded65d3c
Is there any other way to fix this

@kirillgroshkov
Copy link

@gabrielaraujof fix helped me!

@phani1kumar
Copy link

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

Found it via npm/npm#1259

@gibfahn
Copy link
Member

gibfahn commented Sep 10, 2017

Doing what @gabrielaraujof suggested I could not create /var/www to copy my app files to. Tried to chmod and chown without success. Any suggestion?

@ julianonunes

sudo mkdir /var/www? If that doesn't work does it already exist (ls -l /var/www)?

@julianonunes
Copy link

@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

@flinhong
Copy link

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

@gtiguy92
Copy link

@BoiseBaked solution worked for me.

@taewdy
Copy link

taewdy commented Feb 26, 2018

@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

@asottile
Copy link

npm_config_user=root npm install -g ...

works for me

@bhavin-ch
Copy link

Doing this before npm i ... worked for me:

sed -i'' -r 's/^( +, uidSupport = ).+$/\1false/' /usr/local/lib/node_modules/npm/node_modules/uid-number/uid-number.js

@toby5box
Copy link

This works for me too: #1236 (comment)

But I have no idea whether it's the right thing to do or whether there is a real bug somewhere.

@saaryab
Copy link

saaryab commented Mar 19, 2019

npm_config_user=root npm install -g ...

works for me

I added "npm config set user root" before npm install

@bduffany
Copy link

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

@lhoussin
Copy link

lhoussin commented Apr 7, 2021

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

@popovserhii
Copy link

yarn helped me. Try to use:

sudo yarn add global <package>

@nodejs nodejs locked as resolved and limited conversation to collaborators Mar 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests