'How to resolve rename error during npm install
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?
Solution 1:[1]
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.
Solution 2:[2]
After running "npm cache clean", deleting the node_modules folder in the project and then running "npm install" again, fixed this!
Solution 3:[3]
working under windows 10 I opened the CMD as an administrator and that fixed my issue.
Solution 4:[4]
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.
Solution 5:[5]
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
Solution 6:[6]
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.
Solution 7:[7]
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.
Solution 8:[8]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sandeep Rao |
Solution 2 | praveen_r |
Solution 3 | Jeffery ThaGintoki |
Solution 4 | |
Solution 5 | Ismael |
Solution 6 | 1523carver |
Solution 7 | Ayushi Keshri |
Solution 8 | Lucy Johnston |