Your cache folder contains root-owned files

Viewed 2995

Trying to run npm ci on a git deployment branch for my website but receiving the following error;

npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /home/storm/.npm
npm ERR! errno -13
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 1010:1010 "/home/storm/.npm"

I tried running the command it suggests but this doesn't work because there's no such file or directory of "/home/storm/.npm"

I can't find any answers online! Please help

2 Answers

There are multiple ways to solve the described issue. It depends on how you run npm.

Option 1: Adapt the access rights on the npm cache files / folder. Just run the suggested command where 'storm' is your user name and '1010' are your user ID and group ID. (User ID and group ID sometimes differ.)

sudo chown -R 1010:1010 "/home/storm/.npm"

Option 2: Remove the npm cache by running the following command:

sudo npm cache clean --force 

Option 3: Instruct npm to user another directory for caching (avoid using the default npm cache folder). Run the following command before running npm.


export npm_config_cache=/path/to/cache

In my case I ran yarn / npm in a CI/CD pipeline on a Jenkins agent and faced the same issue. Option 3 worked for me. I adapted my pipeline and replaced the command

gradle testAndCoverageWithYarn

with

export npm_config_cache=npm-cache && gradle testAndCoverageWithYarn

(The gradle task testAndCoverageWithYarn calls yarn / npm.)

I had this issue and this command worked for me:

sudo npm cache clean --force 

If this issue sill occured try :

sudo chown -R 1010:1010 "/home/storm/.npm"

Good Luck ;-) I hope it works for You! Watch out for typos ..

Related