No access permission error with npm global install on docker image No access permission error with npm global install on docker image docker docker

No access permission error with npm global install on docker image


The problem is because while NPM runs globally installed module scripts as the nobody user, which kinds of makes sense, recent versions of NPM started setting the file permissions for node modules to root. As a result module scripts are no longer allowed to create files and directories in their module.

See discussion in NPM issue #3849, for some references.

A simple workaround, which makes sense in a docker environment, is to set the NPM default global user back to root, like so:

npm -g config set user root

After which you shouldn't have any more EACCES errors.


Use the --unsafe-perm flag:

npm install --quiet --no-progress --unsafe-perm -g @angular/cli@latest firebase-tools

I think that's still better than setting the npm user permanently to root. You can use --unsafe-perm only with the packages which cause problem


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

This is my dockerfile now:

FROM node:latestUSER nodeRUN mkdir /home/node/.npm-globalENV PATH=/home/node/.npm-global/bin:$PATHENV NPM_CONFIG_PREFIX=/home/node/.npm-globalRUN npm install --quiet --no-progress -g @angular/cli@latest firebase-toolsRUN npm cache clean --force