52

I'm trying to install an npm package (node-xmpp-server) but it fails to install. Previously when I'm trying to install a package that is install globally instead of locally, but now it's not installing at all. I'm running bash as administrator.

I ran:

npm install node-xmpp-server

The error is:

npm ERR! errno -4048
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "c:\\Program Files\\nodejs\\node.exe" "c:\\Program
Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "node-xmpp-server"
npm ERR! node v0.12.4
npm ERR! npm  v2.10.1
npm ERR! path c:\Users\Jaseem Abbas\Documents\node_modules\node- xmpp-server\examples
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! Error: EPERM, unlink 'c:\Users\Jaseem Abbas\Documents\node_modules\node-xmpp-server\examples'
npm ERR!     at Error (native)
npm ERR!  { [Error: EPERM, unlink 'c:\Users\Jaseem Abbas\Documents\node_modules\node-xmpp-server\examples']
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   path: 'c:\\Users\\Jaseem Abbas\\Documents\\node_modules\\node-xmpp-server\\examples' } npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! error rolling back Error: EPERM, unlink 'c:\Users\Jaseem Abbas\Documents\node_modules\node-xmpp-server\examples'
npm ERR! error rolling back     at Error (native)
npm ERR! error rolling back  { [Error: EPERM, unlink 'c:\Users\Jaseem
Abbas\Documents\node_modules\node-xmpp-server\examples']
npm ERR! error rolling back   errno: -4048,
npm ERR! error rolling back   code: 'EPERM',
npm ERR! error rolling back   path: 'c:\\Users\\Jaseem Abbas\\Documents\\node_modules\\node-xmpp-server\\examples' }
2

21 Answers 21

116

Kill whatever process is locking your files

It seems like this kind of error can be caused by a file permissions lock - I experienced something very similar (the same ERRNO: -4048) when installing whatwg-fetch.

I found that a Visual Studio instance I had open at the same time was acquiring all kinds of files which it didn't need. Once I closed that down, the install worked perfectly.

This may be a quickly-checked possible cause to eliminate before moving on to more drastic measures...

6
  • 5
    This deserves more upvotes than it has. I had forgotten about a local ember server I was running in the background when I had stupidly uninstalled and reinstalled ember-cli. This probably saved me several hours of work. Thank you.
    – Cameron
    Commented May 25, 2017 at 20:12
  • 3
    Wow, closed Visual Studio Code and the package installs worked. Curious as to what exactly is causing this as it's gonna be a pain to close and re-open VS Code whenever I want to add a new package.
    – HaulinOats
    Commented Nov 15, 2017 at 23:11
  • This also apparently applies to the Atom IDE as well, so it's not just a Visual Studio issue, although I will say that I've never seen this on my Linux install at home, just the Windows install at work.
    – Mike
    Commented Nov 20, 2017 at 17:24
  • Ditto, I was running an Angular server while trying to npm install. Killed it, immediately worked. Commented Dec 18, 2018 at 11:05
  • Same here, at home I can run multiple vscode instances on my mac just fine but it seems that at work on windows I run into this issue. So it has something to do with how VS Code is handling its open instances on windows specifically. I am on windows 7.
    – Jose
    Commented Jan 2, 2019 at 22:25
15

if you still have troubles with this error and maybe you upgrade the node version to 5.4 > ... that version presents an error. here the solution that basically consist in downgrade node version

In Windows will be:

npm install -g [email protected]

That's works for me.

0
9

I was having the same problem and I found the following solution:

  1. remove both of

    • %ProgramFiles%\nodejs\npm
    • %ProgramFiles%\nodejs\npm.cmd
  2. Go into %ProgramFiles%\nodejs\node_modules\npm and copy the file named npmrc in the new npm folder, which should be %appdata%\npm\node_modules\npm. This will tell the new npm where the global installed packages are.

  3. Restart Windows and it worked.

Found this over here (the npm troubleshooting section). Credits to the authors there

4
  • I tried this but not work for me. I think I deleted some file node file that's by it happened but I uninstall node completely and reinstall but still It's not working any idea what's going wrong? Commented Aug 19, 2015 at 14:16
  • Still the same error? Platform and version of node?
    – Jan_dh
    Commented Aug 19, 2015 at 18:07
  • window 8.1 npm-2.13.4 and node - v0.12.5 Commented Aug 20, 2015 at 4:26
  • in my case it just because i forget that i open some node module with other program, close the program solve the problem. I use win 8 Commented Jul 31, 2017 at 6:26
4

It seems that this error can manifest for more than one reason, so there probably won't be a single fix which works for everyone.

However, concurrency issues often are the cause of the failing installs. According to the accumulated wisdom in one of the related npm issue threads, which has received nearly 180 comments so far, the underlying problem is

a race condition between asynchronous I/O operations accessing the same files on the harddisk. You can certainly influence it by cleaning up the harddisk e.g. with "npm cache verify" or moving the project to a SSD, but this does not solve the root cause of the problem.

Likewise, closing the IDE or disabling the virus scanner works sometimes, for some people, but does not really fix the problem for good if concurrency issues are behind it.

A patch has landed in npm 5.6.0. According to initial reports, it seems to do the trick. So if your npm --version is lower, update to 5.6.0 (or whatever the current version is when you read this):

npm uninstall -g npm
npm install -g [email protected]

as suggested here.

If that doesn't help, then perhaps a file lock is the true cause. And closing the IDE, or disabling the virus scanner temporarily, or some similar action is indeed the way to go, as @Oly has said above.

2
  • dude I ran your command and am stuck with npm version 5.6.0.... it keeps telling me cb.apply is not a function when I try to update or remove npm... thanks a lot man Commented Jul 23, 2022 at 6:17
  • This will get you stuck with this version. cb.apply is not a function, even when you try to revert your version back.
    – Tony
    Commented Dec 27, 2023 at 17:13
3

Upgrade npm to 5.4.2 it will fix this problem.

Command to install : npm i -g [email protected] or npm i -g npm

if still doesn't work try clearing cache using npm cache clean

you can use force like this npm cache clean --force

1
  • 1
    I tried every other steps mentioned in other comments. But finally, this is the only step that worked for me.
    – roney
    Commented Oct 27, 2017 at 21:36
3

Had the same issue Closing visual studio solved the problem

1

Someone said it was due to npm bug https://github.com/npm/npm/issues/9696

Adding "--force" to install allegedly works around the problem.

1
  • I tried doing this and it gave me a message saying I sure hope you know what you're doing.
    – Cameron
    Commented May 25, 2017 at 20:13
1

For me @Oly's solution worked, I'll just add for Angular folks that it was ng serve -o that had locked the files. Yep - don't run npm install while ng serve is running for the project.

1

In my case, I right clicked the json file that was mentioned in the error, Unchecked the read only flag, and it worked

0

I had this same problem, after setting up node.js I followed parts of a guide intended for unix and ended up moving my current working directory to a new folder, but I forgot to copy the .npmrc file from the old location to the new one. I also changed the location of my prefix away from %AppData%, which I found by using npm config ls -l to compare my current settings to the default. The two clues here were that I had a line at the start called userconfig pointing to my .npmrc file, which was in a different location, and that my prefix was overridden from the default value. Changing this back to the default fixed the problem.

Try resetting these to the defaults and check what your config settings are. I'm not sure if reinstalling node.js would help anything if it was still referencing your old settings.

0

I tried following solutions, I don't know which one worked for me.

  • Ran reactive-native init in command prompt as Administrator (on Windows OS), hoping works well with sudo reactive-native init on Mac OS
  • Ran npm cache clean command in Command prompt.
  • Disable your antivirus for time being.

Try any of the solution or all,

0

This is a long standing issue with npm that they seem to have no interest in fixing. Various things others are mentioning will work sometimes (e.g. closing running programs, downgrading the version, etc...). It's been generally limited to Windows installations, though I've even had it happen a bit in Linux lately as well.

0
np init

This will create a dummy package.json. Open the file and enter your required dependencies list.

Now go for:

npm i

This fixed the problem for me.

0

In my case fetch same issue. Then first I stopped npm run watch then try again then it works.

0

I had this same issue, and determined that it was caused by having link-sharing enabled for the Google Drive folder that my project was in. Once I moved it to a non-link-sharing folder everything worked fine.

0

If you have XAMPP server running in the background, kill it.

Then run the installation again.

Worked like magic for me

-1

I had the same problem...here is the fix:

install nodejs in your local directory that does not need admin privilege.

1
-1

I changed the npm version and this did not happen again

-1

I just run npm cache clean, and worked for me

-1

Delete package-lock.json

and try again

-1

Do the followings. This might be permission issue.

  1. Uninstall all antivirus program and restart system
  2. Install yarn
  3. Delete package.lock.json and node_modules folder (if any)
  4. Clear the cache (npm cache clean --force)
  5. Close VS code or other code editor tool (If opened)
  6. now run yarn install

This should resolve the issue.

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