简体   繁体   中英

npm ERR! Error: EPERM: operation not permitted, rename

When I execute npm install I get this error

npm ERR: Error: EPERM, operation not permitted: rename C:\projects******\node_modules\react-async-script' -> 'C.\projects*******\node_modules.react-async-script.DELETE'

  • I am running the cmd as administrator
  • I ran npm cache clean before
  • I made sure all the other applications don't have anything related to node_modules open

In my situation this helped:

Before proceeding to execute these commands close all VS Code instances.

  1. clean cache with

     npm cache clean --force
  2. install the latest version of npm globally as admin:

     npm install -g npm@latest --force
  3. clean cache with

     npm cache clean --force
  4. Try to install your component once again.

I hope this fix your issue. If not, you may temporarily disable your antivirus program and try again.

I got it working when tried npm install with a force option to fetch remote resources even if a local copy exists on disk. Try running

npm install --force

Updated For some of my colleagues this solution was not working. But we tried using yarn instead of npm. It works (faster as well) without any issues all the time

yarn install [package-name]

Not package.json , but for whatever reason, my node_modules/ had become read-only. Resetting that fixed this.

For me i just closed the Code editor (VS Code) and then run the same command. And that solves the issue for me.

If you want to avoid the --force option (which is always a better approach) , I suggest making sure that you have stopped running the project, as this is usually the main reason for locking the files in almost 90% of the cases I have seen

I suggest the following steps in this order:

1- In Angular stopping ng s and in React stopping npm start usually solves this issue because usually this error happens if a development server is running the project as it locks some files & then npm can't update them thus throwing this error

2- If the above doesn't work, then try closing the code editor that has the workspace opened in it (maybe it was locking some files or something)

So try closing the code editor & running:

npm install

3- If still it doesn't work, then maybe you can try the --force option

npm install --force

I was getting that same error and according to https://github.com/Medium/phantomjs/issues/19 it could be caused by your antivirus software. I disabled mine for the duration of the install and executed "npm install" on cmd as admin and it worked. Hope this helps.

As Martin Kearn pointed out in a comment, closing Visual Studio resolved these npm permission issues for me. Evidently VS sometimes locks files in node_modules .

I was getting the same thing. I didn't find this anywhere but it hit me that our VMs tend to change files to a read-only state. So I opened package.json 's file properties and deselected Read-only in the "General" tab.

Steps

  1. Go to the package.json file.
  2. Right-click and select Properties .
  3. In the General tab, Attributes section, deselect Read-only .
  4. Click Apply to apply the change.

This is a typical error caused by Antivirus. There is a workaround for cases like mine, where I can't disable A/V (Company Policy).

You have to change the polyfills.js inside Npm package:

[NODE_HOME]/node_modules/npm/node_modules/graceful_fs/polyfills.js

Look for this statement:

if (process.platform === "win32") {

Inside of this statement, there is a timeout making a retry in case of error. The problem is that in some cases, after the timeout, the file is still locked by the A/V. The solution is rip out the timeout and let this statement in loop. The change with the previous code commented:

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)
}

I have had this issue multiple times only in Windows I try these in the order usually.

  1. npm install --force
  2. Check if node_modules is set to read-only and remove if it is
  3. Delete node_modules/
  4. Check if any editor is opened that could have access to the root folder of the project
  5. Reboot :(

Usually trying npm install after one of those steps will resolve it.

就我而言,某些东西被锁定,快速重启解决了它。

尝试将文件重命名为另一个已经存在的文件名可能会导致 Windows 上的EPERM错误。

关闭 PHPStorm 为我解决了这个问题。

只需关闭 VS Code 即可为我解决问题

I had the same problem after updating to npm to 5.4.2, npm start giving the same error for most npm commands. Some solution suggest to run it with --no-optional , but it didn't always work.

Others suggested to downgrade, but I didn't want to downgrade.

I suspected that there was a problem with the installation, not sure what it was.

So I re-updated my npm:

npm i -g npm

and worked fine since then.

I did the following:

  1. Upgraded the npm to the latest version: npm install -g npm@6.5.0-next.0
  2. deleted the npm-cache folder from: c:/users/[username]/AppData/Roaming/npm-cache
  3. Did cache clean : npm cache clean --force
  4. Ran the npm install .

I remounted my window disks with the metadata flag, and instantly helped: https://devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/

after that no need anymore to use sudo for npm commands as the metadata keeps windows and linux file/directory permissions in check.

npm was failing for me at scandir for:

npm install -g webpack

...which might be caused by npm attempting to "modify" files that were potentially locked by other processes as mentioned here and in few other github threads. After force cleaning the cache, verifying cache, running as admin, disabling the AV, etc the solution that actually worked for me was closing any thing that might be placing a lock the files (ie restarting my computer).

I hope this helps someone struggling.

I had the same problem. The reason for the error is unsupported characters in the path to the file. Replaced the cyrillic in English - it helped.

For some, AppRoot\\npm folder could be an issue. Sometimes the AppRoot folder is marked as network shared and thus Antivirus blocks the stuff. Follow below link for complete solution.

https://alastaircrabtree.com/fixing-intermittant-eperm-operation-not-permitted-on-npm-install/

I hope this helps.

Open the command prompt as administrator and navigate to the project location and then run npm install. it worked for me.

In my case running npm: v6.9.0 && node: v10.16.1 on Windows , I had to run my CLI (git bash) as administrator . Then packages were installed without any warnings/errors

If you are having the issue on PHP Storm:

  1. Close terminal tab
  2. Open a new terminal tab

我在 VSCode 中使用终端,我意识到我使用的是bash终端而不是node终端。

以管理员身份运行 CLI 总是为我解决问题

I am using macOS catalina ,

      npm init 

I got error

       operation not permitted, uv_cwd

in 2021, this is how you can fix this problem.

very simple:

step 1: go to parent folder

         cd ../
         

step 2: go to your project folder again,

         cd  your-project-folder

That is it. it works.

My answer is to do npm cache clean --force first. Then run npm install -g npm@5.3.0 to install npm 5.3.0 version. for me, this npm version works with no trouble.

Just delete the package folder from the path of npm global packages. then reinstall the package. Note that the packages are globally installed in: C:\\Users\\your-name\\AppData\\Roaming\\npm\\node_modules

I was having the same problem in windows 10. Just follows these steps :

  • Open cmd as administrator.

  • install uppdated npm package.

  • npm i -g npm

  • npm init --yes

Running commands as Super Admin worked for me. Retry after closing Editor your are working in.

When I execute npm install I get this error

npm ERR! Error: EPERM: operation not permitted, rename C:\\projects******\\node_modules\\react-async-script' -> 'C:\\projects*******\\node_modules.react-async-script.DELETE'

  • I am running the cmd as administrator
  • I ran npm cache clean before
  • I made sure all the other applications don't have anything related to node_modules open

When I execute npm install I get this error

npm ERR! Error: EPERM: operation not permitted, rename C:\\projects******\\node_modules\\react-async-script' -> 'C:\\projects*******\\node_modules.react-async-script.DELETE'

  • I am running the cmd as administrator
  • I ran npm cache clean before
  • I made sure all the other applications don't have anything related to node_modules open

When I execute npm install I get this error

npm ERR! Error: EPERM: operation not permitted, rename C:\\projects******\\node_modules\\react-async-script' -> 'C:\\projects*******\\node_modules.react-async-script.DELETE'

  • I am running the cmd as administrator
  • I ran npm cache clean before
  • I made sure all the other applications don't have anything related to node_modules open

I closed VS, deleted the node_modules folder.

Then ran:

npm i -D -E clean-webpack-plugin@3.0.0 css- 
loader@3.4.2 html-webpack-plugin@3.2.0 mini-css- 
extract-plugin@0.9.0 ts-loader@6.2.1 typescript@3.7.5 
webpack@4.41.5 webpack-cli@3.3.10 

Then had to change the property to not read only on node_modules folder once it got done running.

Then ran:

npm i @microsoft/signalr @types/node

Then opened back up the project in VS and the package.json looked right with the dependencies.

Along the same lines as others talking about read only on node_modules folder and closing down VS to run npm install over.

After a lot of try I resolved this with following steps:

 0. Run `cmd` or `powershell` as admin
  1. clean cachec npm clean cache --force
  2. delete insides of %AppData%/npm-cache/
  3. delete %temp%
  4. Delete the npm module which is causing the error. For me it was iconv . So deleted iconv and iconv-lite
  5. When I built again, I got failure reason as a virus inside app-builder . I ran windows defender on node-module and removed that virus. Then, build again.
  6. This time I was successful.

These steps solved for me

Go to the package.json file in the file explorer Right click & select Properties. Deselect Read-only. Click Apply

NOTE: (In case if it is already deselected , check and uncheck the read-only once and click Apply)

Most likely the node_modules folder became Read Only . You can try updating folder permissions but if you do not have admin access, the npm install --force will work.

I'm using iTerm. After restarting iTerm, the error was gone.

就我而言,我只是使用 cmd 以管理员身份运行 npm install

I was facing the same issue, Used npm cache clear command in cmd with open as Adminitrator . Close VScode and reopened it. and it worked.

In my case, I had a Windows Explorer opened to the node_modules directory causing issue. Closing this did the trick.

In my case it was the fact that I actually moved the project to Trash, re-cloned the project from git, but seems like Terminal was still pointing to the folder moved in Trash. I only had to cd back to newly cloned project, and everything worked just fine.

In my case I was doing a fs.renameSync when this error happened.

It seems that the "new" path already exists and deleting it doesn't throw an error.

It doesn't really fix the issue but if you just wanna build the app just like I do, then this works.

  1. I reinstall NodeJS
  2. Closed VSCode
  3. Open VSCode to where the project was to get it to run without issues

I came here with the same error, followed all the answers here, and none solved it. I started going through my package.json removing all suspicious packages. Removing this unnecessary one solved our problem. "npm": "^8.3.2"<\/code>

"

I think it should be related to updating npm issue. As a workaround for now you can specify npm version as 8.3.1.

  - name: Install latest npm version
    run: npm install --global npm@8.3.1

July 2022, I'm updating Angular 13 to 14 and I faced this issue. None of the above solutions worked so I just restarted the laptop and the npm i --force worked It seems like one process on the background is locking the access to certain node_modules files (you may have an ng serve running somewhere, or been launched by a git bash which you close but kept running on the background)

This simple remady works for me

  • Open PowerShell with un as administrator

在此处输入图像描述

  • Run this command

    npm i

I face this issue multiple times. It turns out, that it has nothing to do with permissions, cache, etc. The error message is misleading. For node v 6.x you will see more detailed error stack but not after 7.x For me and my colleges, the issue is timeout function. Basically the package install has not finished yet (ie holding the directory) when npm tries to delete it. in node 6.x you can see that in finalize.js now it's gone! Just use yarn.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM