npm install error Error: EPERM: operation not permitted, rename

Reason 1: Insufficient permissions

Open a terminal as an administrator and execute the command.

Reason 2: cache error

method 1

  1. Delete the .npmrc file under C:\Users{account}\
  2. Delete the node_modules folder
  3. Excuting an ordernpm cache clean -f
  4. Then execute the install command

Method 2

  1. Delete the node_modules folder
  2. Excuting an ordernpm cache clean -f
  3. Restart the computer
  4. Execute the install command again

Reason 3: The npm version is not enough

  1. implementnpm install [email protected]
  2. Execute the installation command

Reason 4: The network is unstable

method 1

  1. Switch the download source of npm:npm config set registry https://registry.npm.taobao.org
  2. Check the current download source: npm config get registry, if the result is the Taobao source above, the switch is successful
  3. Execute the install command again

Method 2

  1. After the installation command add--registry https://registry.npm.taobao.org

Attach the official source address: registry https://registry.npmjs.org/

Reason 5: Antivirus software issues

method 1

Turn off the anti-virus software, and then run this installation command several times

Method 2

  1. Find the file:[NODE_HOME]/node_modules/npm/node_modules/graceful_fs/polyfills.js
  2. Look for the following in it:
if (process.platform === "win32") {
    
    
//或者是
if (platform === "win32") {
    
    
  1. Below the found location, modify the file to be
/*
说明:
在这个语句中,有一个超时,在出现错误时进行重试。
问题是,在某些情况下,在超时之后,文件仍然被A/V锁定。
解决方案是去掉超时并让这个语句循环。对先前代码的更改进行了注释:
*/

if (platform === "win32") {
    
    

fs.rename = (function (fs$rename) {
    
     return function (from, to, cb) {
    
    
  var start = Date.now()
  var backoff = 0;
  fs$rename(from, to, function CB (er) {
    
    
    if (er
        && (er.code === "EACCES" || er.code === "EPERM")
        /*&& Date.now() - start < 60000*/) {
    
    
            console.log("Retrying rename file: " + from + " <> " + to)
            fs$rename(from, to, CB);
      /*setTimeout(function() {
        fs.stat(to, function (stater, st) {
          if (stater && stater.code === "ENOENT")
            fs$rename(from, to, CB);
          else
            cb(er)
        })
      }, backoff)*/
      if (backoff < 100)
        backoff += 10;
      return;
    }
    if (cb) cb(er)
  })
}})(fs.rename)
}

Others: to be added

Guess you like

Origin blog.csdn.net/weixin_45795947/article/details/129824156