node.js - npm ERR! Error: EPERM: operation not permitted, rename

ID : 20377

viewed : 6

Tags : node.jswindowsnpmnode.js

Top 5 Answer for node.js - npm ERR! Error: EPERM: operation not permitted, rename

vote vote

97

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.

vote vote

90

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] 
vote vote

71

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

vote vote

69

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

vote vote

54

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 

Top 3 video Explaining node.js - npm ERR! Error: EPERM: operation not permitted, rename

Related QUESTION?