您的缓存文件夹包含 root 拥有的文件

问题描述 投票:0回答:3

尝试在我的网站的 git 部署分支上运行 npm ci,但收到以下错误;

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"

我尝试运行它建议的命令,但这不起作用,因为没有这样的文件或目录“/home/storm/.npm”

我在网上找不到任何答案!请帮忙

node.js npm
3个回答
6
投票

有多种方法可以解决所描述的问题。这取决于你如何运行 npm。

选项1: 调整 npm 缓存文件/文件夹的访问权限。只需运行建议的命令,其中“storm”是您的用户名,“1010”是您的用户 ID 和组 ID。 (用户 ID 和组 ID 有时不同。)

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

选项2: 通过运行以下命令删除 npm 缓存:

sudo npm cache clean --force 

选项3: 指示 npm 使用另一个目录进行缓存(避免使用默认的 npm 缓存文件夹)。在运行 npm 之前运行以下命令。


export npm_config_cache=/path/to/cache

就我而言,我在 Jenkins 代理上的 CI/CD 管道中运行yarn / npm 并遇到了同样的问题。选项 3 对我有用。我调整了管道并替换了命令

gradle testAndCoverageWithYarn

export npm_config_cache=npm-cache && gradle testAndCoverageWithYarn

(gradle任务

testAndCoverageWithYarn
调用yarn / npm。)


0
投票

我遇到了这个问题,这个命令对我有用:

sudo npm cache clean --force 

如果仍然出现此问题,请尝试:

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

祝你好运;-) 我希望它对你有用!注意错别字..


0
投票

我尝试了所有方法,但没有一个对我有用。然后我用自制程序下载了它:

brew install aws-cdk
© www.soinside.com 2019 - 2024. All rights reserved.