Error: EPERM: operation not permitted, unlink 'D:\Sources\**\node_modules\fsevents\node_modules\abbrev\package.json'
Npmpackage.jsonNpm Problem Overview
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 :-(
Npm Solutions
Solution 1 - Npm
I was able to fix this by running the command prompt/bash as admin and closing VSCode! Seems like VSCode was locking some files. Potentially something else could be locking these files for you.
Solution 2 - Npm
It is an npm 5.4.0 issue https://github.com/npm/npm/issues/18287
Workarounds are
- downgrade to 5.3
- try running with --no-optional, i.e.
npm install --no-optional
Solution 3 - Npm
If you downgrade to 5.3 and still get the same error in Windows like me.
After hours working with npm versions I found the following solution:
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 Update npm to 5.3 with npm i -g [email protected]
command line
Now you should use npm without any issues.
Solution 4 - Npm
Please close all IDE like visual studio code. run npm install command through node.js command prompt. Enjoy !
Solution 5 - Npm
cache clean and npm
update to latest with force work for me
npm cache clean --force
npm install -g npm@latest --force
Solution 6 - Npm
I fixed by downgrading npm from 5.4.0 to version 5.3
npm i -g npm@5.3
I Hope this helps for you
Solution 7 - Npm
I tried this solution found at a How to fix Node.js blog
just use
npm cache clean
in windows if it refuses use
npm cache clean --force
Solution 8 - Npm
I had the same issue and all I needed to do was login to npm
npm login
or alternatively
npm add user
// consult the documentation for the params
Solution 9 - Npm
I had the same problem on Windows.
The source of the problem is simple, it is access permission on folders and files.
In your project folder, you need
- After cloning the project, change the properties of the folder and change the permissions of the user (give full access to the current user).
- Remove the read-only option from the project folder. (Steps 1 and 2 take a long time because they are replicated to the entire tree below).
- Inside the project folder, reinstall the node (npm install reinstall -g)
- Disable Antivirus. (optional)
- Disable Firewall. (optional)
- Restart PC.
- Clear the npm cache (npm clear)
- Install the dependencies of your project (npm install)
After that, error "Error: EPERM: operation not permitted, unlink" will no longer be displayed.
Remember to reactivate the firewall and antivirus if necessary.
Solution 10 - Npm
If all of the above failed to work for you, you might want to
- restart your system
- run command prompt as admin
- run the npm command
Solution 11 - Npm
In my case, the problem was that, I did not install typescript. Although I did install Node and Angular. To check if you have installed typescript or not
Run this command: tsc -v
If not, then to install typescript
Run this command: npm install -g typescript
And, finally to install required dependencies
Run this command: npm install
in the root folder of the project.
---- Hope this helps someone ----
Solution 12 - Npm
For those who are coming from Windows OS, you just need to stop the development server and then execute your npm install ...
command.
It is strange how Windows doesn't allow installing dependencies while server is running, but MacOS does allow. If this doesn't work, then only go for the other options - clean cache, downgrade nodejs etc.
Solution 13 - Npm
I had this logs in Windows. I did the following
- Close Visual Studio Code
- Run Command Line as admin
Solution 14 - Npm
Deleting package-lock.json fixed it for me.
Solution 15 - Npm
I'm using VsCode
and solved this issue by stopping the application server and them run npm install
. There are files that were locked by the application server.
No need to close the IDE, just make sure there's no another process locking some files on your projects.
Solution 16 - Npm
For me it worked in bash from git package try:
C:\Program Files\Git\bin\bash.exe
then:
npm install mds.angular.datetimepicker@latest
Solution 17 - Npm
There seems to be many solutions out there that worked with downgrading npm versions. For me, the solution was
npm install -force
I tried the downgrading of npm versions, modifying my npm prefix config to match the npm directory, and clearing cache. None of these worked, but apparently they worked for others, so it may be worth a shot.
Solution 18 - Npm
For me on Windows the problem was too long path length. I moved the project to a smaller length path and it worked.
Solution 19 - Npm
Mine was as a result of opening my project folder a 2 different terminals. I solved it by closing all running terminal (vs code was excluded) and executing the installation command again.
I hope this helps someone.
NB: deleting node_modules didn't solve it.
Solution 20 - Npm
Deleting my node modules folder and running a normal npm install did it for me
Solution 21 - Npm
For me it was Docker...
The moment that I closed the app container, I could do an npm install without any proble
P.S My node version is 14.15.5
Solution 22 - Npm
I fixed this by removing the dist folder
--- Remove dist or public folder
Solution 23 - Npm
the same error comes to me when i update the npm version to the latest 5.4
issuses in npm 5.4
downgrade to the version 5.3.0 is useful.the error comes from the npm 5.4,you can check it in thenpm install npm@5.3 -g
Solution 24 - Npm
Fixed in NPM 5.6.0
Upgrade to NPM 5.6.0 solved problem for me.
Solution 25 - Npm
I wanted to run npm install from within my external hard drive as this is where i saved my code workspace. Windows 10 OS.
But I was getting the same error as the original post.None of the previous answers worked for me, I tried all of them:
- uninstalling nodejs then re-installing
- uninstalling nodejs then downgrading/installing a lower version of nodejs.
- npm install -force
- deleting the folders from C:\Users{YourUsername}\AppData\Roaming ... npm and npm-cache then re-installing.
- npm cache clean --force
- npm cache clean
- npm install --g or npm install --global
What worked for me was this:
- copy the folder from C:\Program Files\nodejs to D:\Program Files\nodejs
- Then go to Control Panel\System and Security\System
- Advanced System Settings
- Environment Variables
- System Variables
- Double click Path
- Add a new path
- D:\Program Files\nodejs
- Click ok
- restart PC.
- try npm install from within D: Drive
Solution 26 - Npm
npm cache verify
solved my issue.
I was doing: ng new my-app
and I faced similar error
I have
node version: 10.16.0
npm v 6.9.0
Solution 27 - Npm
After trying everything, including node/npm upgrade, cache cleaning and reverting code, nothing helped besides one simple thing: Turning OFF Windows 10's Real-time protection during the dev/build. Looks like latest updates made it super aggressive.
Solution 28 - Npm
npm login
is required before publish
Solution 29 - Npm
For windows,
- Download latest recommended version of
nodejs
, these days isnode-v6.11.3-x64
- Uninstall nodejs with it.
- Go to
C:\Users\{YourUsername}\AppData\Roaming
folder and deletenpm
andnpm-cache
folders - Run installer of
nodejs
again and install it - By default
npm 3.10.10
should be installed along withnode-v6.11.3-x64
. - It worked for me with
npm 3.10.10
but did not work with5.3.X
. Also it did not worked with higher versions of node (abovenode-v6.11.3-x64
)
Solution 30 - Npm
My problem was executing the command (npm audit fix all). I solved it when closing VSCODE and re-executed the command without problems.
Solution 31 - Npm
I simply completely shutdown , NOT hibernated, my machine and restarted it. Ran the CMD as admin and used npm install command. It worked.
Solution 32 - Npm
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: https://stackoverflow.com/questions/44310188/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.
Solution 33 - Npm
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
Solution 34 - Npm
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!
Solution 35 - Npm
try running :- 'rm -rf node_modules && npm i' . it worked for me .
Solution 36 - Npm
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.
Solution 37 - Npm
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.
Solution 38 - Npm
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
Solution 39 - Npm
This did the magic for me:
- Close all editors/IDEs and other open consoles.
- Open a new cmd prompt in the project folder.
- Run the command
npm install node-sass@^4.14.1
- Run the command
npm install --no-optional
P.S.: My node version was above 14.
Solution 40 - Npm
For me npm cache clean --force
and restart
Worked Fine!
Solution 41 - Npm
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.
Solution 42 - Npm
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.
Solution 43 - Npm
It happens when "you re-create directory" but already have a shell at this location, so we could simply run in terminal:
cd ~ && cd -
Solution 44 - Npm
THIS WORKED FOR ME
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
then update ,
npm i -g npm
Solution 45 - Npm
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.
Solution 46 - Npm
Just "Restart your system" and try to delete that file again. It should work.