Debugging issues with NPM and updating Node Versions with NVM

A common problem with NPM is setting up your project with a Node version that is lower than the version used by recent packages in NPM.

Trying to do an install in a project will at most times bring about errors complaining about the versions.

This can bring big issues especially when you try to build on or make an update to a previous project that you happened to use a different version of Node to install the packages.

Quick Fix

A quick fix to this problem usually is to install the packages forcefully to your project and this will at most times be the solution.

This will forcefully install packages that are compatible or cloase to being compatible to the current version of Node in your system.

Other fixes

Using Node Version Manager(NVM)

This is a version manager that is made specifically made for managing and installing specific versions of Node.

It is a project that is actively maintained and you can get it from Github and set it up depending on your operating system.

I will show the set up guide for Linux and MacOS. To get a guide on how to set it up on Windows, you can follow the guide here. NVM

To set it up on Linux or Mac, do the following;

This works if you have curl installed.

If you have wget installed, you can also use it.

After installing it, you should restart your terminal for it to read in and reflect.

Open up your terminal and you should be able to access the nvm command.

You can now choose the version that you want or rather install the current Long Term Support Version which is usually recommended.

To install a specific version,

To install the Long Term Support Version,

This should now work and you have node together with NPM installed.

However, if you have installed two or more versions of Node with NVM, you will need to specify the version that you want to use.

To do this,

Now you are good to go with solving NPM issues using NVM.

Using Docker

Another common and much much better way to solve NPM issues is to always build and package your project with Docker.

By doing so, Docker will create and image and store your packages with the version of Node that you specified.

As long as your project remains packaged with Docker, there will be no issues with your packages since Docker will install the packages correctly using the Node version that you specified.

The beauty of Docker also comes in where you can run the same project on different environments or Operating Systems and Docker will reproduce everything with no issues at all.

You will usually specify this inside a Docker file in every project that you make like this one below.

This will set up everything correctly and the environments can now be reproduced.

With the following set ups, you should no longer have issues with NPM again.

Let’s Connect



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Odhiambo Edward

Talented Full-Stack Software Developer with a love for HTML, CSS, SASS, LESS, Vanilla JavaScript, React, Redux, NodeJs, JestJs, Ruby, Ruby on Rails and Database