node.js 安装 npm 包失败“npm ERR!errno -4048”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30860795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:52:14  来源:igfitidea点击:

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

node.jsnpmnode-xmpp

提问by Vishnu Mishra

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 包 (node-xmpp-server),但安装失败。以前当我尝试安装全局而不是本地安装的软件包时,但现在根本没有安装。
请帮帮我。

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

npm install node-xmpp-server
错误是:npm ERR!错误号 -4048
npm 错误号!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!节点 v0.12.4
npm ERR!npm v2.10.1
npm ERR!路径 c:\Users\Jaseem Abbas\Documents\node_modules\node-xmpp-server\examples
npm ERR!代码 EPERM
npm ERR!错误号 -4048
npm 错误号!错误:EPERM,取消链接 'c:\Users\Jaseem Abbas\Documents\node_modules\node-xmpp-server\examples'

npm ERR!在错误(本机)
npm ERR!{ [错误:EPERM,取消链接'c:

错误!错误号:-4048,
npm 错误!代码:'EPERM',
npm 错误!路径:'c:\Users\Jaseem Abbas\Documents\node_modules\node-xmpp-server\examples' } npm ERR!
错误!请尝试以 root/管理员身份再次运行此命令。
错误!错误回滚错误:EPERM,取消链接'c:\Users\Jaseem Abbas\Documents\node_modules\node-xmpp-server\examples'

npm ERR!错误回滚错误(本机)
npm ERR!错误回滚 { [错误:EPERM,取消链接 'c:\Users\Jaseem
Abbas\Documents\node_modules\node-xmpp-server\examples']
npm ERR!错误回滚 errno: -4048,
npm ERR! 错误回滚代码:'EPERM',
错误!错误回滚路径:'c:\Users\Jaseem Abbas\Documents\node_modules\node-xmpp-server\examples' }

回答by Oly

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.

似乎这种错误可能是由文件权限锁定引起的 - 我在安装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.

我发现我同时打开的一个 Visual Studio 实例正在获取它不需要的各种文件。一旦我关闭它,安装工作完美。

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

在采取更严厉的措施之前,这可能是一个快速检查的可能原因以消除...

回答by Fabian Stevens Varon Valencia

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

如果您仍然遇到此错误的问题,并且您可能将节点版本升级到 5.4 > ...该版本会出现错误。这里的解决方案基本上包括降级节点版本

In Windows will be:

在 Windows 中将是:

npm install -g [email protected]

That's works for me.

这对我有用。

回答by Jan_dh

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.

  1. 删除两者

    • %ProgramFiles%\nodejs\npm
    • %ProgramFiles%\nodejs\npm.cmd
  2. 进入 %ProgramFiles%\nodejs\node_modules\npm 并将名为 npmrc 的文件复制到新的 npm 文件夹中,该文件夹应该是 %appdata%\npm\node_modules\npm。这将告诉新的 npm 全局安装的包在哪里。

  3. 重新启动 Windows,它起作用了。

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

这里找到了这个(npm 故障排除部分)。感谢那里的作者

回答by hashchange

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

但是,并发问题通常是安装失败的原因。根据其中一个相关 npm 问题线程中积累的智慧,迄今为止已收到近 180 条评论,潜在的问题是

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.

访问硬盘上相同文件的异步 I/O 操作之间的竞争条件。您当然可以通过清理硬盘来影响它,例如使用“npm cache verify”或将项目移动到 SSD,但这并不能解决问题的根本原因。

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.

同样,关闭 IDE 或禁用病毒扫描程序有时对某些人有效,但如果并发问题背后存在,则并不能真正解决问题。

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

补丁已登陆 npm 5.6.0。根据初步报告,它似乎奏效了。因此,如果您npm --version的版本较低,请更新到 5.6.0(或阅读本文时的任何当前版本):

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

as suggested here.

正如这里建议的

If that doesn't help, then perhaps a file lock isthe 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.

如果这没有帮助,那么文件锁定可能真正的原因。关闭 IDE,或者暂时禁用病毒扫描程序,或者一些类似的操作确实是可行的方法,正如@Oly上面所说的那样。

回答by Peter Kahn

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

有人说是由于npm bug https://github.com/npm/npm/issues/9696

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

添加“--force”来安装据称可以解决这个问题。

回答by Surendra Parchuru

Upgrade npm to 5.4.2 it will fix this problem.

将 npm 升级到 5.4.2 它将解决这个问题。

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

安装命令:npm i -g [email protected]npm i -g npm

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

如果仍然不起作用,请尝试使用npm cache clean清除缓存

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

你可以像这样使用强制npm cache clean --force

回答by Mozart Al Khateeb

Had the same issue Closing visual studio solved the problem

有同样的问题关闭视觉工作室解决了这个问题

回答by sashoalm

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

对我来说,@Oly 的解决方案奏效了,我会为 Angular 的人补充一点,就是ng serve -o它锁定了文件。是的 -在项目运行npm install时不要运行ng serve

回答by MH Fuad

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

在我的情况下,获取相同的问题。然后首先我停止了 npm run watch 然后再试一次然后它就可以工作了。

回答by Mustkeem K

Do the followings. This might be permissionissue.

做到以下几点。这可能是权限问题。

  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
  1. 卸载所有杀毒程序并重启系统
  2. 安装纱线
  3. 删除 package.lock.json 和 node_modules 文件夹(如果有)
  4. 清除缓存(npm cache clean --force)
  5. 关闭 VS 代码或其他代码编辑器工具(如果打开)
  6. 现在运行 yarn install

This should resolve the issue.

这应该可以解决问题。