Fail to install npm package “npm ERR! errno -4048”

烈酒焚心 提交于 2019-11-27 01:18:41

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

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.

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

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

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

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

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.

Had the same issue Closing visual studio solved the problem

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.

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.

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,

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.

Delete package-lock.json

and try again

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

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

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

I changed the npm version and this did not happen again

I just run npm cache clean, and worked for me

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!