在使用 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 依赖缓存的问题
-
首先删除 node_modules 目录和 package-lock.json 文件,以确保从头开始
rm -rf node_modules package-lock.json
-
清空 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"
执行此命令,问题解决
最后的安装完依赖,项目成功跑起来了,哦耶✌️