How to downgrade an installed npm package

Posted on Jun 04, 2022

Learn how you can downgrade an npm package to rollback breaking changes

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. 😉

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.