15

I opened the cmd window as administrator and ran npm install on a folder, got this error at one point:

npm ERR! Error: EPERM: operation not permitted, rename 'MyFolder\node_modules\.staging\@angular\common-54da66e9' -> 'MyFolder\node_modules\@angular\common'
npm ERR!     at destStatted (C:\Program Files\nodejs\node_modules\npm\lib\install\action\finalize.js:25:7)
npm ERR!     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:264:29
npm ERR!     at FSReqWrap.oncomplete (fs.js:123:15)

Same seems to work on other machines!

Can someone help me fix this?

ggorlen
  • 44,755
  • 7
  • 76
  • 106
praveen_r
  • 869
  • 2
  • 10
  • 19
  • Does this answer your question? [npm ERR! Error: EPERM: operation not permitted, rename](https://stackoverflow.com/questions/39293636/npm-err-error-eperm-operation-not-permitted-rename) – ggorlen May 21 '23 at 00:45

9 Answers9

16

I had this problem recently at my work place. In my case what I was doing was, I had the project open in the editor(I use VScode, which is cool:)) and then in the cmd window I was trying to run npm install on the same project folder. I got the same error no matter what I did.

The thing that solved the issue for me is, whenever I try to do npm install I close the editor window in which the project is opened and then run npm install from the cmd window. This works without any issues for me.

By the way I have observed that this is only with windows I guess, on my mac I have never encountered this issue.

Sandeep Rao
  • 171
  • 4
  • Weird enough this solves the issue, thanks a lot, I wouldn't have thought of it. I wonder what's happening in the background to cause this. – Olivier JM Jul 23 '20 at 07:42
  • I've been dealing with this issue (slightly different error message) for months at work now. This fixed it. Thank you. – LovingGarlic Jan 27 '21 at 05:27
  • It's honestly frustrating that we're approaching 2023 and I am still having this issue. This doesn't even happen 100% of the time for me - it seems to be random days that I have this issue. – Quiver Sep 07 '22 at 16:31
6

Running npm cache clean, deleting the node_modules folder in the project and then running npm install again fixed this!

ggorlen
  • 44,755
  • 7
  • 76
  • 106
praveen_r
  • 869
  • 2
  • 10
  • 19
2

working under windows 10 I opened the CMD as an administrator and that fixed my issue.

2

Use yarn instead of npm. So yarn install should replace npm install.

I was on npm 6.14.5 where it didn't work. It works with yarn 1.22.0.

I believe the problem is some race condition and my guess would be that it is because the Windows filesystem is much slower than the Linux file system, especially if you access the Windows file system through the Linux WSL (so if you access the files under /mnt/c/... ). So somewhere in the execution of npm it deletes files and later in the program it assumes the deletion is complete and that might not always be the case, hence the error.

Thorkil Værge
  • 2,727
  • 5
  • 32
  • 48
2

If you are using VS Code you can simply open a terminal in VS Code where you want run npm install and it works without issues. Running your app in a terminal outside of VS Code is what causes this, as there is some conflict with having the project folders open in VS Code at the same time. As a general rule, I use the terminal in VS Code for npm install, nodemon, etc. and then run my application in an outside terminal.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
1523carver
  • 49
  • 4
1

I get this sometimes on macOS with current npm version (6.4.1). The way I got it working is by reverting changes to package-lock.json. Basically I just do git checkout package-lock.json, and then npm install works as it should

Ismael Abreu
  • 16,443
  • 6
  • 61
  • 75
1

For me, the problem was that OneDrive was trying to sync the directory I was in. Once I moved the directory to a location that OneDrive does not sync, I was able to run npm install with no errors.

1

For me the issue was OneDrive sync service. That service was using my folder to upload on server. When I was running npm build command I was getting the error as node couldn't rename the required file as it was already in used by OneDrive. I disabled the service and it worked for me. Hope it helps.

Nakul Varge
  • 43
  • 1
  • 7
0

As, one of the answer above says to delete node_module that would take a lot of time if the project is large enough and have many modules, rather than that try npm uninstall then delete the package-json (to avoid any conflict while reinstalling the modules). After that npm install . This worked fine for me.

Ayushi Keshri
  • 680
  • 7
  • 18