报错:npm ERR code EPERM

1 完整错误

npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path D:\NodeJS\node_cache\_cacache\tmp\7bbab18e
npm ERR! errno EPERM
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/webpack: EPERM: operation not permitted, open 'D:\NodeJS\node_cache\_cacache\tmp\7bbab18e'
npm ERR!     at D:\NodeJS\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR!     at async Arborist.[nodeFromEdge] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1061:19)
npm ERR!     at async Arborist.[buildDepStep] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:930:11)
npm ERR!     at async Arborist.buildIdealTree (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
npm ERR!     at async Promise.all (index 1)
npm ERR!     at async Arborist.reify (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:149:5)
npm ERR!     at async Install.install (D:\NodeJS\node_modules\npm\lib\install.js:170:5)
npm ERR!  FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/webpack: EPERM: operation not permitted, open 'D:\NodeJS\node_cache\_cacache\tmp\7bbab18e'
npm ERR!     at D:\NodeJS\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR!     at async Arborist.[nodeFromEdge] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1061:19)
npm ERR!     at async Arborist.[buildDepStep] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:930:11)
npm ERR!     at async Arborist.buildIdealTree (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
npm ERR!     at async Promise.all (index 1)
npm ERR!     at async Arborist.reify (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:149:5)
npm ERR!     at async Install.install (D:\NodeJS\node_modules\npm\lib\install.js:170:5) {
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'open',
npm ERR!   path: 'D:\\NodeJS\\node_cache\\_cacache\\tmp\\7bbab18e',
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.
(base) PS F:\tutorial-frontend\webpack\code> npm i webpack webpack-cli --save-dev
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path D:\NodeJS\node_cache\_cacache\tmp\671f2a33
npm ERR! errno EPERM
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/webpack: EPERM: operation not permitted, open 'D:\NodeJS\node_cache\_cacache\tmp\671f2a33'
npm ERR!     at D:\NodeJS\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR!     at async Arborist.[nodeFromEdge] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1061:19)
npm ERR!     at async Arborist.[buildDepStep] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:930:11)
npm ERR!     at async Arborist.buildIdealTree (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
npm ERR!     at async Promise.all (index 1)
npm ERR!     at async Arborist.reify (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:149:5)
npm ERR!     at async Install.install (D:\NodeJS\node_modules\npm\lib\install.js:170:5)
npm ERR!  FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/webpack: EPERM: operation not permitted, open 'D:\NodeJS\node_cache\_cacache\tmp\671f2a33'
npm ERR!     at D:\NodeJS\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR!     at async Arborist.[nodeFromEdge] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1061:19)
npm ERR!     at async Arborist.[buildDepStep] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:930:11)
npm ERR!     at async Arborist.buildIdealTree (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
npm ERR!     at async Promise.all (index 1)
npm ERR!     at async Arborist.reify (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:149:5)
npm ERR!     at async Install.install (D:\NodeJS\node_modules\npm\lib\install.js:170:5) {
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'open',
npm ERR!   path: 'D:\\NodeJS\\node_cache\\_cacache\\tmp\\671f2a33',
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.

2 错误详解

该错误发生在修改npm的全局安装路径之后,再执行npm install 包 -g或是npm install 包时发生,但是在管理员身份下运行cmd,均能执行成功。

2.1 修改npm全局安装:
  1. 命令行:
  2. npm config set prefix "D:\NodeJS\node_global"
    npm config set cache "D:\NodeJS\node_cache"
    

    在C盘User/用户名/下有一个.npmrc的文件
    将上述node_global文件夹的路径加入环境变量
    2 .2导致该安装问题的原因
    没有管理员权限,无法在node_global和node_cache两个文件夹下进行一些必要的操作

2.3修复方法

  1. 删除用户下的.npmrc文件,即不改变全局安装的路径(不够好,本质问题仍没有解决,全局还是会安装在C盘)
    每次都用管理员身份运行命令行(不够方便,vscode 下的命令行默认也不是管理员身份运行的)
    直接修改node_global和node_cache文件夹的权限:
    右键文件夹,打开属性,切换到安全选项卡

    选择编辑,将没有打钩的位置全部打上钩(即将其它用户的权限设置为与管理员相同),应用即可。
    3 运行测试
    安装webpack测试,成功!
    npm i webpack webpack-cli -g
    npm i webpack webpack-cli --save-dev

相关推荐

  1. IDEA

    2024-01-25 11:36:01       39 阅读
  2. sqoop运行

    2024-01-25 11:36:01       43 阅读
  3. yarn install

    2024-01-25 11:36:01       39 阅读
  4. 安装Paddlehub

    2024-01-25 11:36:01       36 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-25 11:36:01       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-25 11:36:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-25 11:36:01       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-25 11:36:01       20 阅读

热门阅读

  1. 躲避陷阱的优雅之舞:职场误区深度解析

    2024-01-25 11:36:01       39 阅读
  2. [VulnHub靶机渗透] CTF7

    2024-01-25 11:36:01       51 阅读
  3. 如何在 Python 中将语音转换为文本

    2024-01-25 11:36:01       27 阅读
  4. npm ERR! code CERT_HAS_EXPIRED & errno CERT_HAS_EXPIRED

    2024-01-25 11:36:01       30 阅读
  5. C#-Lambda 表达式

    2024-01-25 11:36:01       27 阅读
  6. 鸿蒙开发笔记(二十七): 交互事件--手势

    2024-01-25 11:36:01       28 阅读
  7. MySQL内外连接

    2024-01-25 11:36:01       34 阅读
  8. 安全合规之漏洞扫描的重要意义

    2024-01-25 11:36:01       39 阅读
  9. Python系列(5)—— 作用域

    2024-01-25 11:36:01       34 阅读
  10. 力扣381周赛

    2024-01-25 11:36:01       39 阅读
  11. 一台PC创建多个Git平台账号

    2024-01-25 11:36:01       36 阅读