the_piper
the_piper

Reputation: 105

Jenkins build issue - npm ERR! Your cache folder contains root-owned files

I am trying to build a small node app on my Jenkins pipeline, which is running in a virtual machine. cross this error:

    + npm install
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /.npm
npm ERR! errno EACCES
npm ERR! 
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 111:120 "/.npm"

Running sudo chown -R 111:120 "/.npm" doesn`t help since it says:

chown: cannot access '/.npm': No such file or directory

And, as per my understanding, runs in a local context, when the problem is actually from the container perspective. I`ve tried to add the command above on my Docker and Jenkinsfile as well, to no avail. Below is my public repo:

Node app deploy on github

Upvotes: 6

Views: 12426

Answers (4)

Janne Annala
Janne Annala

Reputation: 28796

It looks like you might be running the official node docker image with a different user than the default node user. You might have overridden it in the Dockerfile or with the docker run --user x parameter.

I just upgraded from node:16 to node:20 and started having this issue. Removing --user someuser or setting it to node fixed the issue.

Upvotes: 0

Firze
Firze

Reputation: 4049

I had the same issue and fixed it by setting the npm cache directory to ENV variable in Dockerfile.

Add this to Dockerfile:

ENV npm_config_cache /home/node/app/.npm

Upvotes: 3

the_piper
the_piper

Reputation: 105

As far as I can remember ,just updating npm version and deleting the whole project did the trick.

Upvotes: -3

zOthix
zOthix

Reputation: 566

npm install --cache=".YourCustomCacheDirectoryName"

works perfectly fine, reason for this is your docker user isn't allowed to write in / ( root directory ) its not that a directory already exist at /.npm its that, your script is trying to create a directory at / which is not accessible for your user you can either put

agent {
    docker {
      image 'node:latest'
      args '-u root:root'
    }
}

or just tell npm to use your custom cache directory

Upvotes: 20

Related Questions