Search code examples
node.jsnpmubuntu-18.04

NPM is really slow performing simple tasks


Everything I do with NPM takes several minutes; especially npm install, even if I already have all the packages installed. I first thought the problem is that the old code I am working with just takes longer to update (because last time an older npm version was used) but the problem percists even if I repeat the process.

My system and other Information:

  • Windows 11 PC
  • Ubuntu 18.04.5 VM from the Microsoft Store
  • VS Code.
  • npm version 8.19.2
  • node version 16.17.0
  • From my package-lock.json file: "lockfileVersion": 2
  • I usally have 5 to 10 dependecies listed in my package file
  • My internet speed is around 25 MB/s

What I tried so far with no luck:

  • A newer Version of Ubuntu
  • Using http instead of https a la:
npm config set registry http://registry.npmjs.org/ --global

as was suggested in 'npm install' extremely slow on Windows. It seems to me it still tries to connect to the https address (at least that's what it looks like if I use npm install --verbose to show more feedback).

No matter what I still sit here, wasting ages waiting for my npm install.


Solution

  • I finaly found a solution. I just did not now to ask the right question.

    The problem was that I was using WSL version 2 and my files are in C: and not the Ubuntu folders. A fix that worked for me was moving to WSL version 1.

    More details can be found here.

    If you're also switching to WSL version 1 and are having problems with node or npm, this might help.