npm安装依赖时报错npm error code EPERM npm error syscall mkdir npm error path D:\node-v20.16.0-x64\node_cach

1、报错内容

npm error code EPERM
npm error syscall mkdir
npm error path D:\node-v20.16.0-x64\node_cache\_cacache
npm error errno EPERM
npm error FetchError: Invalid response body while trying to fetch https://registry.npmmirror.com/@element-plus%2ficons-vue: EPERM: operation not permitted, mkdir 'D:\node-v20.16.0-x64\node_cache\_cacache'
npm error     at D:\node-v20.16.0-x64\node_modules\npm\node_modules\minipass-fetch\lib\body.js:170:15
npm error     at async Response.json (D:\node-v20.16.0-x64\node_modules\npm\node_modules\minipass-fetch\lib\body.js:75:17)
npm error     at async RegistryFetcher.packument (D:\node-v20.16.0-x64\node_modules\npm\node_modules\pacote\lib\registry.js:98:25)
npm error     at async RegistryFetcher.manifest (D:\node-v20.16.0-x64\node_modules\npm\node_modules\pacote\lib\registry.js:128:23)
npm error     at async #fetchManifest (D:\node-v20.16.0-x64\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1199:20)
npm error     at async #nodeFromEdge (D:\node-v20.16.0-x64\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1037:19)
npm error     at async #buildDepStep (D:\node-v20.16.0-x64\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:901:11)
npm error     at async Arborist.buildIdealTree (D:\node-v20.16.0-x64\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:181:7)
npm error     at async Promise.all (index 1)
npm error     at async Arborist.reify (D:\node-v20.16.0-x64\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:131:5) {
npm error   code: 'EPERM',
npm error   errno: 'EPERM',
npm error   syscall: 'mkdir',
npm error   path: 'D:\\node-v20.16.0-x64\\node_cache\\_cacache',
npm error   type: 'system',
npm error   requiredBy: '.'
npm error }
npm error
npm error The operation was rejected by your operating system.
npm error It's possible that the file was already in use (by a text editor or antivirus),
npm error or that you lack permissions to access it.
npm error
npm error If you believe this might be a permissions issue, please double-check the
npm error permissions of the file and its containing directories, or try running
npm error the command again as root/Administrator.
npm notice
npm notice New patch version of npm available! 10.8.1 -> 10.8.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.2
npm notice To update run: npm install -g npm@10.8.2
npm notice
npm error Log files were not written due to an error writing to the directory: D:\node-v20.16.0-x64\node_cache\_logs
npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

2、原因

没有管理员权限,无法在node_global和node_cache两个文件夹下进行一些必要的操作

3、解决

直接修改node_global和node_cache文件夹的权限:
存放全局模块(node_global)和缓存文件(node_cache)。
给这2个文件夹设置权限,右键文件夹->属性->安全tab,选择编辑,将没有打钩的位置全部打上钩(即将其它用户的权限设置为与管理员相同),应用即可。
在这里插入图片描述
在这里插入图片描述
设置新的路径:window+R+cmd 进入终端,通过npm配置命令npm config set prefix 和 npm config set cache来分别指定新的全局模块安装路径和缓存路径;说明:
prefix = 创建的node_global文件夹所在路径
cache = 创建的node_cache文件夹所在路径

npm config set prefix "D:\node-v20.16.0-x64\node_global"
npm config set cache "D:\node-v20.16.0-x64\node_cache"
  • 11
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值