How to Downgrade an Installed npm Package
Learn how to downgrade npm packages for compatibility issues, bug fixes, new features, or personal preference. Follow step-by-step guide for a easy downgrade process.
In the world of web development, npm packages play a crucial role in simplifying and streamlining the development process. However, sometimes we need to downgrade an npm package to an older version due to compatibility issues, or bugs or simply revert back to a more reliable version.
In this article, we will see how to downgrade an installed NPM package to a specific version using the NPM CLI (Command Line Interface).
Understanding npm Packages
Before diving into how to downgrade npm packages, let's first understand what are npm packages and why they are used.
Npm packages are pre-written code modules that we can install and use in our project without having to write everything from scratch. This helps developer to save time and effort and also allows us to concentrate on the core functionality of our project.
Reasons to downgrade npm packages
There can be several reasons why we might want to downgrade an npm package. And some of the most common reasons are:
- Compatibility Issues: The new version might introduce some bugs or compatibility issues in your code and so we might need to downgrade the npm package.
- Bug Fixes: The newer version of the package might introduce some code-breaking bugs in your project.
- Preference for Older Version: If we like some features in the older version which might not be present in the newer one.
So these are some of the few reasons why a developer might choose the older version and revert back to it.
How to downgrade an npm package
We can downgrade an installed npm package by specifying the desired version number in the terminal.
Syntax for downgrading a package:
npm install <package-name>@<version-number>
For example, let's say we want to downgrade the flickity npm package from version 3.0.0 to 2.2.0. So we will write the following code in the terminal:
npm install flickity@2.2.0
The above command will not only downgrade the flickity package version to 2.2.0, it will also update the version number in package.json file.
Alternatively, if we want to downgrade an npm package globally on our computer, we have to use the npm install command with the --global or -g option. This will overwrite the file at the global level or save it as a dependency in your package.json file respectively.
For example, we want to downgrade the axios package from version 1.3.1 to 1.2.0 globally on our computer. So, we will write the following command:
npm install axios@1.2.0 -g
Since we have used the -g option, it will downgrade the whole npm axios packages at global level in our computer.
Conclusion:
From this short article, we have learned downgrading an npm package is a simple and easy process and can be done in a few steps. Whether you, as a developer facing any compatibility issues, bugs with the newer version, or just want to take advantage of the older version, downgrading the npm package can be a helpful solution.
Related Posts
Solve npm ERR! ENOENT - No Such File or Directory Error
Learn what causes the npm ERR! ENOENT error, steps to troubleshoot it, and how to fix the no such file or directory issue when running npm start or npm install commands on your Node.js project.
How to Clear Cache in NPM?
In this tutorial we will learn how to clean or remove npm cache from Windows, linux and Mac using npm cache clean command.
(Fixed) npm ERR! missing script: start error
This article is about how to fix npm err! missing script start error in nodejs application.
Fixed Error - npm ERR! missing script: dev
Find out how to fixed npm error, npm missing script dev while running the node serve in your javascript node project.
