node.js - Why is npm install really slow

node.js – Why is npm install really slow?

node.js – Why is npm install really slow?

I was able to resolve this from the comments section; outlining the process below.

n

From the comments

n

AndreFigueiredo stated :

n

n

I installed modules here in less than 1 min with your package.json with npm v3.5.2 and node v4.2.6. I suggest you update node and npm.

n

n


n

n

v1.3.0 didnt even have flattened dependencies introduced on v3 that resolved a lot of annoying issues

n

n

LINKIWI stated :

n

n

Generally speaking, dont rely on package managers like apt to maintain up-to-date software. I would strongly recommend purging the node/npm combo you installed from apt and following the instructions on nodejs.org to install the latest release.

n

n

Observations

n

Following their advice, I noticed that CentOS, Ubuntu, and Debian all use very outdated versions of nodejs and npm when retrieving the current version using apt or yum (depending on operating systems primary package manager).

n

Get rid of the outdated nodejs and npm

n

To resolve this with as minimal headache as possible, I ran the following command (on Ubuntu) :

n

apt-get purge --auto-remove nodejs npmn

n

This purged the system of the archaic nodejs and npm as well as all dependencies which were no longer required

n

Install current nodejs and compatible npm

n

The next objective was to get a current version of both nodejs and npm which I can snag nodejs directly from here and either compile or use the binary, however this would not make it easy to swap versions as I need to (depending on age of project).

n

I came across a great package called nvm which (so far) seems to manage this task quite well. To install the current stable latest build of version 7 of nodejs :

n

Install nvm

n

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bashn

n

Source .bashrc

n

source ~/.bashrcn

n

Use nvm to install nodejs 7.x

n

nvm install 7n

n

After installation I was pleasantly surprised by much faster performance of npm, that it also now showed a pretty progress bar while snagging packages.

n

For those curious, the current (as of this date) version of npm should look like the following (and if it doesnt, you likely need to update it):

n

current

n

Summary

n

DO NOT USE YOUR OS PACKAGE MANAGER TO INSTALL NODE.JS OR NPM – You will get very bad results as it seems no OS is keeping these packages (not even close to) current. If you find that npm is running slow and it isnt your computer or internet, it is most likely because of a severely outdated version.

I am using Linux and have nvm and working with more than 7 version of nodenAs of my experience I experienced the same situation with my latest project (actually not hours but minutes as I cant wait hours because of hourly project :))

n

Disclaimer: dont try below option until you know how cache clean works

n

npm cache clean --force

n

and then all working fine for me so its looks like sometimes npms cache gets confused with different versions of Node.

n

Official documentation of Npm cache can be found here

node.js – Why is npm install really slow?

I see from your screenshot that you are using WSL on Windows. And, with Windows, comes virus scanners, and virus scanning can make NPM install very slow!

n

Adding an exemption or disabling virus scanning during install can greatly speed it up, but potentially this is undesirable given the possibility of malicious NPM packages

n

One link suggests triple install time https://ikriv.com/blog/?p=2174

n

I have not profiled extensively myself though

Related posts on Node js :

Leave a Reply

Your email address will not be published.