npm安装依赖时报错

1、报错

PS D:\miniprograms\xdemo03> npm i vant-weapp -S --production
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path D:\tools\Bootstrap\nodejs\node_cache\_cacache\tmp\3f4ac2f2
npm ERR! errno EPERM
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npmmirror.com/vant-weapp: EPERM: operation not permitted, open 'D:\tools\Bootstrap\nodejs\node_cache\_cacache\tmp\3f4ac2f2'  
npm ERR!     at D:\tools\nvm-1.1.12-setup\nvm\v16.0.0\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR!     at async Arborist.[nodeFromEdge] (D:\tools\nvm-1.1.12-setup\nvm\v16.0.0\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:945:19)
npm ERR!     at async Arborist.[buildDepStep] (D:\tools\nvm-1.1.12-setup\nvm\v16.0.0\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:891:11)
npm ERR!     at async Arborist.buildIdealTree (D:\tools\nvm-1.1.12-setup\nvm\v16.0.0\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:217:7)
npm ERR!     at async Promise.all (index 1)
npm ERR!     at async Arborist.reify (D:\tools\nvm-1.1.12-setup\nvm\v16.0.0\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:134:5)
npm ERR!     at async Install.install (D:\tools\nvm-1.1.12-setup\nvm\v16.0.0\node_modules\npm\lib\install.js:137:5)
npm ERR!  FetchError: Invalid response body while trying to fetch https://registry.npmmirror.com/vant-weapp: EPERM: operation not permitted, open 'D:\tools\Bootstrap\nodejs\node_cache\_cacache\tmp\3f4ac2f2' 
npm ERR!     at D:\tools\nvm-1.1.12-setup\nvm\v16.0.0\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR!     at async Arborist.[nodeFromEdge] (D:\tools\nvm-1.1.12-setup\nvm\v16.0.0\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:945:19)
npm ERR!     at async Arborist.[buildDepStep] (D:\tools\nvm-1.1.12-setup\nvm\v16.0.0\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:891:11)
npm ERR!     at async Arborist.buildIdealTree (D:\tools\nvm-1.1.12-setup\nvm\v16.0.0\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:217:7)
npm ERR!     at async Promise.all (index 1)
npm ERR!     at async Arborist.reify (D:\tools\nvm-1.1.12-setup\nvm\v16.0.0\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:134:5)
npm ERR!     at async Install.install (D:\tools\nvm-1.1.12-setup\nvm\v16.0.0\node_modules\npm\lib\install.js:137:5) {
npm ERR!   code: 'EPERM',
npm ERR!   errno: 'EPERM',
npm ERR!   syscall: 'open',
npm ERR!   path: 'D:\\tools\\Bootstrap\\nodejs\\node_cache\\_cacache\\tmp\\3f4ac2f2',
npm ERR!   type: 'system',
npm ERR!   requiredBy: '.'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),        
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
PS D:\miniprograms\xdemo03>

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"

npm config set prefix "D:\tools\Bootstrap\nodejs\node_global"
npm config set cache "D:\tools\Bootstrap\nodejs\node_cache"

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值