128

I just updated npm to 5.4.0.
Now, Whenever I want install a npm package I get the following error:

D:\Sources\DownloadCms\Md.Download\Web.Angular>npm install mds.angular.datetimepicker@latest --save
npm ERR! path D:\Sources\DownloadCms\Md.Download\Web.Angular\node_modules\fsevents\node_modules\abbrev\package.json
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'D:\Sources\DownloadCms\Md.Download\Web.Angular\node_modules\fsevents\node_modules\abbrev\package.json'
npm ERR!     at Error (native)
npm ERR!  { Error: EPERM: operation not permitted, unlink 'D:\Sources\DownloadCms\Md.Download\Web.Angular\node_modules\fsevents\node_modules\abbrev\package.jso
n'
npm ERR!     at Error (native)
npm ERR!   stack: 'Error: EPERM: operation not permitted, unlink \'D:\\Sources\\DownloadCms\\Md.Download\\Web.Angular\\node_modules\\fsevents\\node_modules\\ab
brev\\package.json\'\n    at Error (native)',
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'unlink',
npm ERR!   path: 'D:\\Sources\\DownloadCms\\Md.Download\\Web.Angular\\node_modules\\fsevents\\node_modules\\abbrev\\package.json' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Mohammad\AppData\Roaming\npm-cache\_logs\2017-09-03T03_25_50_432Z-debug.log

I'm dead sure, run CMD as administrator.

Also I checked D:\Sources\DownloadCms\Md.Download\Web.Angular\node_modules\fsevents\node_modules\abbrev\package.json\, package.json is not exist in path !

Edit: Upgrade to v5.4.1, still get the same error, even cannot work around with --no-optional :-(

2
  • I'm having this issue on npm 8.5.0, nn-no-optional doesn't work
    – niico
    Commented Mar 26, 2022 at 19:34
  • All I needed to do, was to stop my dev server and retry the command Commented Nov 7, 2023 at 17:58

51 Answers 51

1
2
1

I simply completely shutdown , NOT hibernated, my machine and restarted it. Ran the CMD as admin and used npm install command. It worked.

1

In my case, i was facing similar issue while running multiple instance of 'npm install' on VM used for build(Windows)

Since it was a VM used only for build there was no other program locking the files. I tried disabling various antivirus settings which didn't worked. "npm cache clear" and "npm cache verify" worked but it was not a right solution for me as i cannot guess when somebody will trigger a build job from Jenkins for different release/environment leading to multiple instance of 'npm install' and hence i cannot add it to the build script nor i can go login to VM and clear/delete the cache folders manually every time.

Finally, after some research, I ended up running "npm install" with separate cache path for each job using following command:

npm install --cache path/to/some/folder

Since, all the jobs running at the same time now had a separate cache path rather than the common global path (Users/AppData/Roaming/), this issue got fixed as the jobs were no more trying to lock and access the same file, from the common npm cache.

Please note you can install a single package with a cache path as follows:

npm install packageName --cache path/to/some/folder

I was not able to find this way of giving a cache path in npm documentation but i gave it a try and it worked. I am using npm6 and looks like it works since npm5.

[Refer: How to specify cache folder in npm5 on install command?

This solution should work for other scenarios as well though may or may not be a good fit.

1

This was the only thing that worked for me:

npm cache clean --force

npm install -g npm@latest --force

rm package-lock.json

npm i -force
1

I got the same problem just doing an npm install. Run with antivirus disabled (if you use Windows Defender, turn off Real-Time protection and Cloud-based protection). That worked for me!

1

Having watched my Windows Defender Virus Scanner start hogging the CPU while running my script, I suspect this is the actual cause, but as I don't have the ability to tweak those settings as I'm in a commercial domain.

As my script fails while doing npm install, I simply tried this instead

npm install --verbose

which allowed it to run perfectly. It probably doesn't fix the underlying issue, but it allowed my install to download and extract all dependencies to my local cache at least once and therefore, everything worked a lot smoother.

I presume this command slows the writes/read to the disk by a fraction of a second, while its writing to the Command prompt and this gives the virus checker, just enough time to finish its work, without creating a deadlock on the files.

1

In my case, VS code was opened and also the application was running on the metro bundler, so I just close the metro bundler and use the install command again and it got worked.

1

This did the magic for me:

  1. Close all editors/IDEs and other open consoles.
  2. Open a new cmd prompt in the project folder.
  3. Run the command npm install node-sass@^4.14.1
  4. Run the command npm install --no-optional

P.S.: My node version was above 14.

1

In my case it was the node process that I was debugging that had a lock on some native compiled node-gyp type modules.

As the .node file is effectively a DLL/shared object, the calling process needs to keep a lock on the file so that it can load pieces of the file on demand. If the file were suddenly removed, it would be a problem for the running process.

Stopping the node process being debugged resolved the issue in my case.

Not seeing an answer here that covers this scenario. If this covers your case then it's a quicker resolution than closing or rebuilding everything.

1

I have tried ALL the solutions here. Then I've came up with a solution on a blog. If someone using node-gradle plugin and facing this issue, the following solution might help.

for your .gitignore or .npmignore file, add the following :

# Gradle
.gradle/

It seemed totally irrelevant to me, but after spending 1.5 day on this stupid issue, finally it worked.

1

It happens when "you re-create directory" but already have a shell at this location, so we could simply run in terminal:

cd ~ && cd -
1

THIS WORKED FOR ME

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

then update ,

npm i -g npm

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented May 20, 2022 at 10:01
1
  1. Update your nodejs version node >=16
  2. Update npm version to latest
  3. npm cache clean --force Try again it should work
1

Try running:

rm -rf node_modules && npm i
0

For windows,

  1. Download latest recommended version of nodejs, these days is node-v6.11.3-x64
  2. Uninstall nodejs with it.
  3. Go to C:\Users\{YourUsername}\AppData\Roaming folder and delete npm and npm-cache folders
  4. Run installer of nodejs again and install it
  5. By default npm 3.10.10 should be installed along with node-v6.11.3-x64.
  6. It worked for me with npm 3.10.10 but did not work with 5.3.X. Also it did not worked with higher versions of node (above node-v6.11.3-x64)
0

My problem was executing the command (npm audit fix all). I solved it when closing VSCODE and re-executed the command without problems.

0

I faced the same issue and was not able to solve the problem with any of above mentioned solutions.So I tried moving my project directory to some other location on Desktop.Then it showed, could not do this as it is running, even though I hadn't opened that file in any text editor or so.So what I did was to type resmon.exe in Run commandbox and then clicked the CPU option.Then enlarged the associated handles section and type in the name of my project directory.It showed some processes that were running that directory so I selected them and right clicked them and clicked End Process. Then i was able to cut paste my project directory to some other location on desktop and then i ran npm install commands and was able to successfully execute the.check out this image

1
0

Just "Restart your system" and try to delete that file again. It should work.

0

enter image description here [Error: EPERM: operation not permitted, unlink 'C:\Users\Yogesh\Desktop\hooks\my-app\node_modules@firebase\analytics-compat\dist\index.cjs.js'] { npm WARN cleanup errno: -4048, npm WARN cleanup code: 'EPERM', npm WARN cleanup syscall: 'unlink',

I got a similar error but there was a network issue while installing firebase I recommend seeing an internet connection while installing firebase since small fluctuations may also give the error.

1
0

In my case I had this error because Prisma had the studio open and or because the server was on because I stopped both and tried again and the installation worked

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Apr 11 at 12:23
0

My issue was that I was running the same project in using pm2 in the background. All I did is stop the pm2 process before running other scripts on the same project.

0

If you're using mac os make sure your IDE (e.g Visual Studio) has Full disk Access. You can enable this by following the below settings.

Settings -> Privacy & Security -> Full Dis Access -> Enable toggle for VSCode

I face this issue and solved it by the above mentioned settings.

2
  • You are answering a different question. Based on the content of the question, it’s clear that this is about Windows. Commented Apr 29 at 1:29
  • Even though the machine is different it looks like permission issues. I want to explain that permission is the issue Commented May 3 at 6:12
1
2

Not the answer you're looking for? Browse other questions tagged or ask your own question.