相关文章推荐
犯傻的企鹅  ·  【Android】SVG和VectorDra ...·  3 月前    · 
冷静的勺子  ·  js ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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' }
                once npm and its modules what you want just install in the root folder. Your problem will solve
– Rijo
                Sep 20, 2017 at 15:37

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...

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 May 25, 2017 at 20:12 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 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 Nov 20, 2017 at 17:24 Ditto, I was running an Angular server while trying to npm install. Killed it, immediately worked. – Tanya Branagan 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 Jan 2, 2019 at 22:25

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 npm@5.3

That's works for me.

  • %ProgramFiles%\nodejs\npm.cmd
  • 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.

  • Restart Windows and it worked.

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

    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? – Vishnu Mishra Aug 19, 2015 at 14:16 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 – Adi Prasetyo Jul 31, 2017 at 6:26

    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 npm@5.6.0
    

    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.

    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 – Andrew P. Jul 23, 2022 at 6:17

    Upgrade npm to 5.4.2 it will fix this problem.

    Command to install : npm i -g npm@5.4.2 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

    I tried every other steps mentioned in other comments. But finally, this is the only step that worked for me. – roney Oct 27, 2017 at 21:36 I tried doing this and it gave me a message saying I sure hope you know what you're doing. – Cameron May 25, 2017 at 20:13

    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.

  • 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,

    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.

    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.

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

    Then run the installation again.

    Worked like magic for me

    Hi Ron, Welcome to SO! I suggest you take a read though here (stackoverflow.com/help/how-to-answer) to improve your answer, and potentially gain rep! :) – CalvT May 20, 2016 at 18:11
  • Uninstall all antivirus program and restart system
  • Install yarn
  • Delete package.lock.json and node_modules folder (if any)
  • Clear the cache (npm cache clean --force)
  • Close VS code or other code editor tool (If opened)
  • now run yarn install
  • This should resolve the issue.