docker-node: Command "npm install -g" causes "ERR! Cannot read property 'path' of null"
attempting to enhance this image by installing Elm globally but encountering issues. It would appear that the installation process for npm is user 500 and owns and restricts access to /usr/local/lib/node_modules by default. Seems like an unnecessary constraint to impose on an already isolated environment.
Investigation revealed:
4337 error Linux 4.4.0-21-generic
4338 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "elm"
4339 error node v7.8.0
4340 error npm v4.2.0
4341 error path /usr/local/lib/node_modules
4342 error code EACCES
4343 error errno -13
4344 error syscall access
4345 error Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
4345 error { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
4345 error errno: -13,
4345 error code: 'EACCES',
4345 error syscall: 'access',
4345 error path: '/usr/local/lib/node_modules' }
4346 error Please try running this command again as root/Administrator.
4347 verbose exit [ -13, true ]
and
ls -al /usr/local/lib/node_modules
total 12
drwxrwxr-x 3 500 500 4096 Mar 29 01:27 .
drwxrwxr-x 4 500 500 4096 Mar 29 01:27 ..
drwxrwxr-x 11 500 500 4096 Mar 29 01:27 npm
where
id -nu 500
id: 500: no such user
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 2
- Comments: 28 (15 by maintainers)
I think this is due to run npm as root. You should run it as the
nodeuserI was facing this issue while building the Angular 6 image with Docker (v18.09.0).
The Proxy variables of node and Docker environment were causing the problem. The solution is to reset
httpProxyvariable value as told here: Docker doc. Also, set project specific.npmrclike: gist and fix thenpmpermission issue: gistFinally, my
Dockerfilelooks like:I hope this helps someone.
The solution mentioned here works. https://github.com/nodejs/docker-node/issues/437#issuecomment-320993300
In addition, npm added the
npxcommand for running installed dependencies which significantly simplifies running globally installed modules.