Fail to install npm package: "npm ERR! errno -4048"

117.9k views Asked by At

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' }
21

There are 21 answers

6
Oly On BEST ANSWER

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

0
Fabian Stevens Varon Valencia On

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
Nwaburu Emeka Christian On

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

Then run the installation again.

Worked like magic for me

2
hashchange On

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.

0
Mozart On

Had the same issue Closing visual studio solved the problem

0
user1688136 On

Delete package-lock.json

and try again

0
Mustkeem K On

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
MH Fuad On

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

1
Surendra Babu Parchuru On

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

0
user2689380 On

I changed the npm version and this did not happen again

0
Bhagwat K On

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
Thomas Leamon On

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
Peter Kahn On

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

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

0
sovemp On

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.

4
Jan_dh On

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

0
Ashish On
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
Ash On

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

0
sashoalm On

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
Ron On

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

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

0
Dani Castilho On

I just run npm cache clean, and worked for me

0
Stephen Arsenault On

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.