42
votes

I'm trying to install npm package (node-xmpp-server) but it fail 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.
Plz Help me.

npm install node-xmpp-server
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' }

19
Open your command prompt as an administrator and then try again.Bidhan
@BidhanA I'm running bash as administrator.Vishnu Mishra
once npm and its modules what you want just install in the root folder. Your problem will solveRijo

19 Answers

100
votes

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

15
votes

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.

9
votes

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
votes

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.

3
votes

Had the same issue Closing visual studio solved the problem

1
votes

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
votes

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
votes

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.

0
votes

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
votes

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
votes

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

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

0
votes

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.

0
votes

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.

-1
votes

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

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

-1
votes

I changed the npm version and this did not happen again

-1
votes

I just run npm cache clean, and worked for me

-1
votes

Delete package-lock.json

and try again