“npm install”在 Windows 上非常慢

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29395211/
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-08 19:01:28  来源:igfitidea点击:

'npm install' extremely slow on Windows

windowsnpm

提问by Simon Knittel

For me is npm installextremely slow. I'm using Windows 8.1 with the latest npm version. My connection speed is around 100Mbit/s.

对我来说是npm install极其缓慢的。我正在使用带有最新 npm 版本的 Windows 8.1。我的连接速度大约是 100Mbit/s。

The project I'm trying to install has around 20 packages/dependencies and it takes around 30 Minutes to install all dependencies ...

我尝试安装的项目有大约 20 个包/依赖项,安装所有依赖项大约需要 30 分钟......

Does anyone have a clue?

有人有线索吗?

回答by Christof K?lin

I ran into the same problem, using --verboseas peterh mentioned showed me the source of the problem: I am behind a proxy, which uses its own certificates for https-connections. According to user "Mletter1" on https://github.com/npm/npm/issues/8872the issue is quite easily solved by using http:

我遇到了同样的问题,--verbose正如 peterh 提到的那样向我展示了问题的根源:我在一个代理后面,它使用自己的证书进行 https 连接。根据https://github.com/npm/npm/issues/8872 上的用户“Mletter1” ,使用 http 很容易解决这个问题:

npm config set registry http://registry.npmjs.org/ --global

And voilà, it's fast again. Of course you should only do this, if you're ok with cleartext npm infos over the net ;-)

瞧,它又快了。当然,你应该只这样做,如果你对网络上的明文 npm 信息没问题;-)

回答by Roko C. Buljan

from eternity → to 5 seconds builds:

从永恒 → 到5 秒构建

  • search for Windows Defender settings
  • → Virus & threat protection
  • → Virus & threat protection Settings
  • → Exclusions
  • 搜索Windows Defender 设置
  • → 病毒和威胁防护
  • → 病毒和威胁防护设置
  • → 排除

here add this two paths to your list of excluded realtime protectionfolders:

在这里将这两个路径添加到排除的实时保护文件夹列表中:

C:\Program Files\nodejs
C:\Users\<your username>\AppData\Roaming\npm

PS: replace the <your username>with your respective Userfolder name.
If you're wandering why you can't find the AppDatafolder in Explorer, make sure to check View options for hidden folders.

PS<your username>用您各自的用户文件夹名称替换。
如果您想知道为什么在资源管理器中找不到AppData文件夹,请务必检查隐藏文件夹的查看选项。

Concerns regarding security :hopefully you know what you download to your node_modules folder, do you ;)

关于安全性的担忧:希望您知道您下载到 node_modules 文件夹中的内容,是吗;)

回答by Nikhil Dev

I've been facing the same issue for a while. I was trying out the following

我已经面临同样的问题一段时间了。我正在尝试以下

npm i typescript live-server --save-dev

The install would get stuck at it forever. However adding the -verbose flag worked just fine.

安装将永远卡在它上面。但是添加 -verbose 标志效果很好。

回答by MartinDoes

I know its just a workaround, but try using the build-in "Windows PowerShell"

我知道这只是一种解决方法,但请尝试使用内置的“ Windows PowerShell

回答by Williem

It seems like npm do not deal well with internet connections and can sometimes end in such situation.

似乎 npm 不能很好地处理互联网连接,有时会在这种情况下结束。

1)I'll advice you to check if your firewall or antivirus is not performing any scan or filtering which may slow down npm install.

1)我建议您检查您的防火墙或防病毒软件是否没有执行任何可能减慢 npm 安装速度的扫描或过滤。

2)You may also use caching from npm like below.

2)你也可以像下面一样使用来自 npm 的缓存。

npm install package-name --cache "c:\path\to\use\as\dependencies\cache"

this will allow npm download and cache dependencies in the directory you specified.

这将允许 npm 在您指定的目录中下载和缓存依赖项。

3)another solution for caching npm packages dependencies is npm lazy, you may find more information about this at npm Lazy website

3)缓存 npm 包依赖项的另一种解决方案是npm lazy,您可以在npm Lazy 网站上找到更多相关信息

Note:the caching process may or may not improve the download speed but it will probably save downloads time when installing or updating your npm packages.

注意:缓存过程可能会也可能不会提高下载速度,但它可能会在安装或更新 npm 包时节省下载时间。

回答by Mike

Turning off Windows Firewall and Windows Defender Real-time protection did it for me in Windows 10.

在 Windows 10 中关闭 Windows 防火墙和 Windows Defender 实时保护对我有用。

回答by Benjamin Casha

For me it appeared to be a problem with IPv6.

对我来说,这似乎是 IPv6 的问题。

Disabling IPv6 helped immensely for me.
With IPv6 turned on "update-package newtonsoft.json" took 1:45 to time out with the error "update-package : A task was canceled."

禁用 IPv6 对我有很大帮助。
启用 IPv6 后,“update-package newtonsoft.json”耗时 1:45 超时,出现错误“update-package : A task was cancelled”。

With IPv6 disabled "update-package newtonsoft.json" completed in 10 seconds

禁用 IPv6 后“更新包 newtonsoft.json”在 10 秒内完成

回答by 10Champ

Turning off the Windows Defender Firewall helped for me.

关闭 Windows Defender 防火墙对我有帮助。

Because it just doesnt feel right I first added the WIFI to a Private Network (via WIFI settings) and only turned off the Windows Defender for a Private Network instead of all public Networks.

因为感觉不对,我首先将 WIFI 添加到专用网络(通过 WIFI 设置),并且只关闭了专用网络的 Windows Defender,而不是所有公共网络。

The next step should be: what network traffic causes this and how to add this to the Windows Defender exception rule :)

下一步应该是:是什么网络流量导致了这种情况以及如何将其添加到 Windows Defender 例外规则中 :)

回答by Trailblazer

I faced the same issue while creating project while using angular cli "ng new PROJECT_NAME" this command triggers "npm -install" after creation of project, which took too long to install, and got stuck at "Installing packages for tooling via npm" . Follow these which worked for me

我在使用 angular cli "ng new PROJECT_NAME" 创建项目时遇到了同样的问题,此命令在创建项目后触发了 "npm -install",安装时间太长,并卡在 "Installing packages for tooling via npm" 。按照这些对我有用

1) Check your npm version "npm --version" (must be higher than 2.1.8)Update your npm package by "npm -g install --save latest-version"

1)检查你的npm版本“npm --version”(必须高于2.1.8)通过“npm -g install --save latest-version”更新你的npm包

2) Remove the progress bar which consumes more time "npm set progress=false"

2) 移除耗时较多的进度条“npm set progress=false”

check this issues if still doesn't fix your problem https://github.com/nodejs/node/issues/4150https://github.com/npm/npm/issues/11283

如果仍然不能解决您的问题,检查此问题 https://github.com/nodejs/node/issues/4150 https://github.com/npm/npm/issues/11283

Hopefully this sorts the problem Cheers!

希望这可以解决问题 干杯!

回答by Prasanth Jaya

I tried all the config's (proxy, registry, etc) nothing worked for me, so did a complete uninstall and install node & npm. Which helped to solve the issue.

我尝试了所有配置(代理、注册表等)对我没有任何作用,所以完全卸载并安装 node & npm。这有助于解决问题。