记一次 npm cache clean --force 时报错 Your cache folder contains root-owned files, due to a bug in...的解决方案

在使用 npm i 安装依赖包下载依赖的时候报错

npm error code EEXIST
npm error syscall mkdir
npm error path /Users/jingxuehui/.npm/_cacache/content-v2/sha512/a6/f1
npm error errno -13
npm error EACCES: permission denied, mkdir '/Users/jingxuehui/.npm/_cacache/content-v2/sha512/a6/f1'
npm error File exists: /Users/jingxuehui/.npm/_cacache/content-v2/sha512/a6/f1
npm error Remove the existing file and try again, or run npm
npm error with --force to overwrite files recklessly.
npm error A complete log of this run can be found in: /Users/jingxuehui/.npm/_logs/2024-09-19T05_46_55_206Z-debug-0.log

考虑是 npm 依赖缓存的问题

  1. 首先删除 node_modules 目录和 package-lock.json 文件,以确保从头开始

    rm -rf node_modules package-lock.json
    
  2. 清空 npm 缓存

    npm cache clean --force
    

    请注意,--force 选项是必需的,因为默认情况下,npm不允许完全清空缓存。这个命令会删除所有缓存数据,确保你的后续安装使用的是最新的包。

    ⚠️ 就在执行此命令遇到如下报错信息:

    ➜  main-web git:(develop)npm cache clean --force
    npm warn using --force Recommended protections disabled.
    npm error code EACCES
    npm error syscall rmdir
    npm error path /Users/jingxuehui/.npm/_cacache/index-v5/42/9e
    npm error errno -13
    npm error
    npm error Your cache folder contains root-owned files, due to a bug in
    npm error previous versions of npm which has since been addressed.
    npm error
    npm error To permanently fix this problem, please run:
    npm error   sudo chown -R 501:20 "/Users/jingxuehui/.npm"
    npm error A complete log of this run can be found in: /Users/jingxuehui/.npm/_logs/2024-09-19T05_47_42_447Z-debug-0.log
    

    “npm ERR! Your cache folder contains root-owned files” 这段字面描述很清楚,你的缓存目录中包含 root 权限的文件,所以因为你没有权限操作这个文件就报错了。

    解决方法:

    上面写的很明白了 To permanently fix this problem, please run:,要永久修复此问题,请运行:

    sudo chown -R 501:20 "/Users/jingxuehui/.npm"
    

    执行此命令,问题解决

    最后的安装完依赖,项目成功跑起来了,哦耶✌️

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

八了个戒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值