28

I have node v.4.4 with npm v.2.14.20 (default bundled with windows installer). My OS: Windows 7 64bit. Hardware: Dell laptop, 16GB RAM, SSD, core i7.

I'm facing a problem with extremely slow npm. For example when I want to check version of node with

node --version
v4.4.0

I receive output 4.4.0 within miliseconds. But when I type

npm --version

I need to wait ridiculous 8-15 seconds to receive an output! And it's the same with every single npm command.

What i tried: update npm (to most recent 3.x version), update node to 5.9.0, i also tried my luck with x86 versions - same thing.

  1. Any clues what can cause such "sleep" (it's only with npm, every other cmd command works fine, system works fine)?
  2. I will appreciate any tips how I can debug this thing to see what's going on under the hood
Mic
  • 313
  • 1
  • 3
  • 6
  • 1
    any luck with this ? http://stackoverflow.com/questions/29395211/npm-install-extremly-slow-on-windows – Rabea Mar 19 '16 at 20:50
  • nope, I tried both disabling IPv6 and symantec endpoint protection (this is what I have on this laptop) - without any effect. However, when I tried eg. `npm view grunt` twice the second shot (i guess from cache) takes about 6 seconds (so it's faster than first one which is about 16 sec)... – Mic Mar 19 '16 at 21:10
  • Any further update other than the above? Thanks! – MoMo Oct 25 '16 at 14:40
  • npm is actually a batch script running node. How long does it take to start your command line application? – Jonas Köritz Nov 06 '16 at 09:03
  • Did you ever find a fix for this problem? – Nicholas K Feb 02 '20 at 13:26
  • I'm curious to know why do you use such old version of node? – Sang Dang Apr 28 '20 at 07:47

6 Answers6

3

I had similar problems regarding npm being slow. Ive researched for hours on possible solutions. The only solutions that worked for me was either disabling the progress bar with npm config set progress false --global Or using a different terminal such as git bash or windows terminal.

Josh Merlino
  • 622
  • 6
  • 10
1

I am betting you have a lot of items in your PATH. This a common symptom of that scenario.

In your terminal, run:

echo "$PATH"

If the output has more than 8 or 9 colons in it, or if there are big directories like the root directory / in there, then this very well may be the culprit.

As a basis for comparison, my carefully crafted PATH on macOS is:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

And if I run which npm, the output is:

/usr/local/bin/npm

This tells me that my npm is located early in my PATH, which is important for performance, as the PATH gets searched from left to right for the existence of npm within each directory.

You can quickly try out my PATH from above without any permanent consequences by simply running:

OLDPATH="$PATH"
PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

Now try running the commands that were previously fast and slow and see if there is any difference.

If you start seeing "command not found" errors, try incrementally adding things back to your PATH or simply run:

PATH="$OLDPATH"

Otherwise, if performance remains the same, then it is probably not your PATH. But if the situation improved, read on to make it permanent.

Take the PATH that works best for you and put it in your shell's startup file. This will typically be located at ~/.bashrc or ~/.bash_profile. Try to find the startup file that already has a PATH=... line, comment out the existing line (be sure to add an explanatory comment) and then insert a similar line with the better value.

Seth Holladay
  • 8,951
  • 3
  • 34
  • 43
  • 2
    I bet this is for Unix or something like that. But this question is about Windows, not Unix –  Mar 14 '17 at 13:24
  • 1
    Windows is clearly mentioned in the original question. This answer is irrelevant. – thordarson Feb 27 '20 at 09:46
  • @thordarson my answer applies to Windows, but yes I showed Unix-y examples. To be fair, most Node.js development on Windows is done using Windows Subsystem for Linux (WSL) these days. My answer is applicable regardless of whether you are using WSL, but the example commands should work as-is on WSL. – Seth Holladay May 12 '20 at 05:48
1

Try using git bash instead of CMD

Algo7
  • 2,122
  • 1
  • 8
  • 19
0

Upgrade your NPM & NodeJS.

Harsh Srivastava
  • 376
  • 2
  • 10
0

Disable Firewall / Antivirus

If your machine belongs to a company, it may contain firewall / antivirus which delay every command in the command line.

I faced the same issue when every git command took 10+ seconds.

When trying to diagnose the problem with the IT department, we saw that when disabling firewall / antivirus in Windows 7, everything works much faster (as it should).

Upgrade to Node15

It's the latest stable version of NodeJs. Node comes with Npm so you will get the latest Npm as well automatically.

Stav Alfi
  • 13,139
  • 23
  • 99
  • 171
-1

Following Seth Holladay answer but with solution to Windows

Go to my computer
Right click on my computer and select properties at the bottom
Look at the left labels, click on the additional system parameters
Click environment variables at the bottom
Here you can change user env variables at the top and system wide env variables at the bottom

Plush
  • 1