How to revert back to an older NPM package version
After updating a NPM package, sometimes we can discover the updated version can cause an unexpected bug in our projects.
If we are sure it was working before the update, reverting back to the older version may be a good choice until the issues have been resolved.
Taking a random NPM package, we install in the terminal like this:
// using npm npm i jsonwebtoken // using yarn yarn add jsonwebtoken
At the time of writing, this would install the jsonwebtoken package at the latest version of 8.5.1.
To change back to an earlier version, all we need to do, is to re-install the package, specifying the version number:
// using npm npm i firstname.lastname@example.org // using yarn yarn add email@example.com
Which then sets our package back to the earlier version of 8.4.2.
This also works for global packages too using the -g flag.