• 报错:npm ERR code EPERM


    1 完整错误

    npm ERR! code EPERM
    npm ERR! syscall open
    npm ERR! path D:NodeJS
    ode_cache_cacache	mpbbab18e
    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
    ode_cache_cacache	mpbbab18e'
    npm ERR!     at D:NodeJS
    ode_modules
    pm
    ode_modulesminipass-fetchlibody.js:162:15
    npm ERR!     at async Arborist.[nodeFromEdge] (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarboristuild-ideal-tree.js:1061:19)
    npm ERR!     at async Arborist.[buildDepStep] (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarboristuild-ideal-tree.js:930:11)
    npm ERR!     at async Arborist.buildIdealTree (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarboristuild-ideal-tree.js:216:7)
    npm ERR!     at async Promise.all (index 1)
    npm ERR!     at async Arborist.reify (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarborist
    eify.js:149:5)
    npm ERR!     at async Install.install (D:NodeJS
    ode_modules
    pmlibinstall.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
    ode_cache_cacache	mpbbab18e'
    npm ERR!     at D:NodeJS
    ode_modules
    pm
    ode_modulesminipass-fetchlibody.js:162:15
    npm ERR!     at async Arborist.[nodeFromEdge] (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarboristuild-ideal-tree.js:1061:19)
    npm ERR!     at async Arborist.[buildDepStep] (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarboristuild-ideal-tree.js:930:11)
    npm ERR!     at async Arborist.buildIdealTree (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarboristuild-ideal-tree.js:216:7)
    npm ERR!     at async Promise.all (index 1)
    npm ERR!     at async Arborist.reify (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarborist
    eify.js:149:5)
    npm ERR!     at async Install.install (D:NodeJS
    ode_modules
    pmlibinstall.js:170:5) {
    npm ERR!   code: 'EPERM',
    npm ERR!   syscall: 'open',
    npm ERR!   path: 'D:\NodeJS
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62

    ode_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: utorial-frontendwebpackcode> npm i webpack webpack-cli --save-dev
    npm ERR! code EPERM
    npm ERR! syscall open
    npm ERR! path D:NodeJS
    ode_cache_cacache mp71f2a33
    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
    ode_cache_cacache mp71f2a33’
    npm ERR! at D:NodeJS
    ode_modules
    pm
    ode_modulesminipass-fetchlibody.js:162:15
    npm ERR! at async Arborist.[nodeFromEdge] (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarboristuild-ideal-tree.js:1061:19)
    npm ERR! at async Arborist.[buildDepStep] (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarboristuild-ideal-tree.js:930:11)
    npm ERR! at async Arborist.buildIdealTree (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarboristuild-ideal-tree.js:216:7)
    npm ERR! at async Promise.all (index 1)
    npm ERR! at async Arborist.reify (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarborist
    eify.js:149:5)
    npm ERR! at async Install.install (D:NodeJS
    ode_modules
    pmlibinstall.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
    ode_cache_cacache mp71f2a33’
    npm ERR! at D:NodeJS
    ode_modules
    pm
    ode_modulesminipass-fetchlibody.js:162:15
    npm ERR! at async Arborist.[nodeFromEdge] (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarboristuild-ideal-tree.js:1061:19)
    npm ERR! at async Arborist.[buildDepStep] (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarboristuild-ideal-tree.js:930:11)
    npm ERR! at async Arborist.buildIdealTree (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarboristuild-ideal-tree.js:216:7)
    npm ERR! at async Promise.all (index 1)
    npm ERR! at async Arborist.reify (D:NodeJS
    ode_modules
    pm
    ode_modules@npmcliarboristlibarborist
    eify.js:149:5)
    npm ERR! at async Install.install (D:NodeJS
    ode_modules
    pmlibinstall.js:170:5) {
    npm ERR! code: ‘EPERM’,
    npm ERR! syscall: ‘open’,
    npm ERR! path: ‘D:\NodeJS
    ode_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. 命令行:

      npm config set prefix "D:NodeJS
      ode_global"
      npm config set cache "D:NodeJS
      ode_cache"
      
      • 1
      • 2
      • 3
      • 4

      在C盘User/用户名/下有一个.npmrc的文件

    2. 将上述node_global文件夹的路径加入环境变量

    2.2 导致该安装问题的原因

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

    2.3 修复方法

    1. 删除用户下的.npmrc文件,即不改变全局安装的路径(不够好,本质问题仍没有解决,全局还是会安装在C盘)
    2. 每次都用管理员身份运行命令行(不够方便,vscode 下的命令行默认也不是管理员身份运行的)
    3. 直接修改node_globalnode_cache文件夹的权限:
      1. 右键文件夹,打开属性,切换到安全选项卡
        在这里插入图片描述
      2. 选择编辑,将没有打钩的位置全部打上钩(即将其它用户的权限设置为与管理员相同),应用即可。

    3 运行测试

    安装webpack测试,成功!
    npm i webpack webpack-cli -g
    npm i webpack webpack-cli --save-dev

    先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦

  • 相关阅读:
    纯c语言版单链表(上)
    linux下doc转docx
    leetcode:滑动窗口----3. 无重复字符的最长子串
    读取yml文件
    【Vue】v-bind对样式控制的增强-操作class
    【计算机网络-自顶向下方法】应用层(SMTP、POP3、DNS)
    SpringCloud 04 Eureka 服务注册和发现
    Java多线程笔记
    高通的camera的dts配置说明
    第十三章---枚举类型与泛型
  • 原文地址:https://blog.csdn.net/m0_67401417/article/details/126081302