How to downgrade an installed npm package

npm packages are frequently updated to make the package more useful and solve existing bugs.

Sometimes, you may find that a newer npm package version breaks your application.

To downgrade an npm package, run the npm install <package>@<version> command. You need to provide the version you want to install with the @<version> syntax.

For example, Vue version 3 introduces a notable amount of breaking changes from Vue 2.

When you need to downgrade Vue from version 3 to version 2, use the command below:

npm install vue@2

npm will overwrite the vue package already installed in your node_modules/ folder.

When you provide only the major version as in the example above, then npm will install the latest vue@2 version, which is version 2.6.14.

To install an exact version, you need to explicitly define the major, minor, and patch version like this:

npm install vue@2.1.7

The above command installs Vue exactly version 2.1.7.

You can also do the same with globally installed packages. Just add the -g option to the npm install command as follows:

npm install -g vue@2.3.1

The above command will overwrite the vue package installed at the global level.

And that’s how you downgrade an npm package. 😉

Get 100 JavaScript Snippets Book for FREE 🔥

100 JavaScript snippets that you can use in various scenarios

Save 1000+ hours of research and 10x your productivity