'npm install' extremely slow on Windows
Asked Answered
N

17

118

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

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

Does anyone have a clue?

Nightshirt answered 1/4, 2015 at 15:45 Comment(7)
I'm having this issue today too. Reasonably freshly built windows 8.1 box, I installed node.js and npm today. npm install is running very slow when trying to install bower. npm v2.7.4 nodejs v0.12.2Untruthful
@Simon Knittel Have you solved it ?Torn
@PantaRhei I don't know if it is the solution but it made a difference for me whether I install the modules on an USB3 drive or an internal HDD.Nightshirt
@simon it can be your firewall blocking connection otherwise make you update Nodejs and npmZamudio
@Pnta you can try update Nodejs and npm and disable firewallZamudio
Brah.. same here. I am planning on migrating to mac. It has the best of both worlds(Unix and pro apps).Lanta
I unplugged from my networks ethernet and used wifi. This sped the installation 1,000xShamus
A
44

I ran into the same problem, using --verbose as 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/8872 the issue is quite easily solved by using 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 ;-)

Azotobacter answered 21/11, 2016 at 13:48 Comment(4)
Just ran into this when using Windows WSL against a VirtualBox Docker (Toolbox). NPM slow as mud, redirecting my WSL (debian) to http npmjs.org sped things up significantly.Musculature
To add another helpful link, looks like WSL NPM usage is also impacted by Windows Defender. gist.github.com/noelbundick/9c804a710eb76e1d6a234b14abf42a52Musculature
But isn't that unsafe? Exposes you the MIM attacksSorry
Great answer! However, now it is required to use https: npm config set registry https://registry.npmjs.org/ --globalAmundsen
R
44

Warning regarding security: this is an insecure approach if you don't use any other means of antivirus protection.

From eternity → to 5 seconds builds:

  • search for Windows Defender settings
  • → Virus & threat protection
  • → Virus & threat protection Settings
  • → Exclusions

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

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

PS: replace the <your username> with your respective User folder name; or use alias to the AppData folder like: %AppData%\npm
If you're wondering why you can't find the AppData folder in Explorer, make sure to check "View" options for "Show hidden folders".

Riddick answered 13/8, 2018 at 17:4 Comment(11)
It works great for me, should also add in the workspace folder, where you have local node_modules folders for projects.Flossieflossy
@Chet let me know when you make it work what you didRiddick
I went into the defender and turned off all virus and threat protection, all network and firewall protection, turned off "check apps and files". I also turned added some npm settings to turn of progress, and set the registry url to http instead of https. Its a bit faster now.Lingual
@Lingual yap, viruses infections should go faster now 🙈Riddick
That's the plan! 🤞Lingual
you save my dayFruge
This is for me the best answer.Elusive
Just type in %appdata% in your explorer. Will take you to roaming folderAarika
Why NodeJS build is considered harmful by anti-virus?Ulberto
If you are using nvm for windows you should change the path to "C:\Users\<your username>\AppData\Roaming\nvm"Etruscan
Did it for me as well, probably not the safest, but having globally installed clis probably trigger windows defender to check all the node_modules files and hence the slow initial run. After first run its fine, still annoying like a hell, so i also just exclude the folder (in my case the nvm symlinked folder)Turbinal
D
13

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

Desmonddesmoulins answered 12/4, 2017 at 18:9 Comment(4)
Worked fine! Thanks.Imperfection
@Desmonddesmoulins Why is PowerShell faster?Juristic
Same exact performance between cmd.exe and PowerShell for me.Trichloroethylene
But, why, can we know why.Elusive
J
10

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.

Jemadar answered 28/10, 2015 at 15:29 Comment(2)
But why -verbose makes a difference?Dilly
@Dilly most like not, its the cold start of npm that is slow, when i tried it again it would have been fast. nothing to do with -verboseTurbinal
M
5

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

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.

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

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.

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

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.

Merras answered 18/4, 2015 at 17:15 Comment(0)
K
4

For me it appeared to be a problem with 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."

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

Kristoforo answered 17/11, 2015 at 15:53 Comment(1)
Disabling IPv6 helped me with similar issue on Fedora 23Neumann
M
3

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

Minnick answered 25/2, 2017 at 15:51 Comment(1)
this would disable basic protection of the whole computer. Roko's answer reduce the exposure to only node folders.Sateia
A
3

Fully turning off virus and firewall protection isn't the safest option. While it makes things faster, it leaves you more vulnerable.

In my case, I only excluded the node.exe process in virus & threat protection.

  • In your start menu, type "windows security" and open the app.
  • Click on "Virus & threat protection"
  • Virus & threat protection settings => Manage settings
  • Exclusions => Add or remove exclusions
  • Add an exclusion => process => type node.exe => click Add

just a simple create-react-app went down from 2m40s to 1m10s npm commands are also executed by node.exe, so the same improvements are noticed there.

Archaize answered 30/7, 2020 at 1:36 Comment(0)
G
2

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

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"

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

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

Hopefully this sorts the problem Cheers!

Grove answered 17/4, 2017 at 14:9 Comment(0)
L
2

In my case it was due to over 200 vulnerabilities. When I ran

npm audit fix

that solved only just a few of them. Eventually, I had to run

npm audit fix --force

and it got way better than before.

Lacunar answered 18/2, 2021 at 12:57 Comment(0)
N
1

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.

Nth answered 9/8, 2018 at 13:40 Comment(0)
M
1

Turning off the Windows Defender Firewall helped for me.

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.

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

Microorganism answered 27/10, 2019 at 7:3 Comment(0)
D
1

in addition to all other great comments, I'd also suggest switching to yarn (https://marketplace.visualstudio.com/items?itemName=geeklearningio.gl-vsts-tasks-yarn). using devops (selfhosted agent v.2.192.0), with node (v.14.17.6), we were able to trim total build (install + build) from ~10min to ~6-7 min.

Dibromide answered 10/9, 2021 at 17:31 Comment(0)
I
0

Make sure you really are using a recent version of npm. In my case C:\Program Files\nodejs\npm.cmd had been using an old npm-cli.js below the default prefix folder %appdata%\npm rather than a newer npm-cli.js below C:\Program Files\nodejs.

Setting the environment variable npm_config_prefix to C:\Program Files\nodejs solved that. (Before finding that solution, I tried using the --prefix argument and found out the hard way doing so "forces non-global commands to run in the specified folder".)

I found a huge performance increase going from 3.10.9 to 6.13.4-- enough to make npm install times acceptable despite interference from antivirus.

Intervene answered 6/8, 2020 at 20:45 Comment(0)
P
0

I just went through a rabbit hole trying to identify the issue. If npm install keeps getting bottlenecked you should heavily consider modifying the properties of your virtual ethernet and disable all of the offload items.

I had 0 proxies or caching issues with npm.

See here for the tutorial on how to get to the menu and disable your offload settings. Make sure you do this for both your your ethernet and VEthernet and you should immediately notice a difference. I went from a 10 minute hanging resolution that sometimes just stopped down to 10 seconds installs. https://www.dincloud.com/blog/tuning-windows-get-15x-speeds-on-large-file-copies-today

Preprandial answered 19/10, 2020 at 7:44 Comment(0)
F
0

This is highly situational but we have a local registry (npm config get registry) that was not available (VPN:d) in when I was running the npm install ... and this obviously made it very slow but it still succeeded because everything was still available through cache.

Faircloth answered 17/10, 2022 at 11:9 Comment(0)
S
0

Try upgrading to the latest Node.js version. I was originally using the most recent LTS (18.x) and downloading packages was painfully slow. I then tried installing the latest 20.x and it instantly solved my download issues.

You may also try adding the --verbose flag (e.g. npm install --verbose) to have an idea on where the process is getting stuck.

Schramm answered 27/8, 2023 at 1:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.