How to resolve rename error during npm install

Viewed 11470

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?

9 Answers

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.

This question is probably long dead, but 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.

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

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.

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.

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.

Related