How to install a previous exact version of a NPM package?
If you need to install a specific older version of an npm package—rather than the latest—append @<version> to the package name. For example, installing version 4.17.11 of lodash:
npm install lodash@4.17.11
Key Points:
- This command installs exactly 4.17.11 of lodash into your local
node_modulesfolder. - It also writes
^4.17.11in yourpackage.jsonby default, unless you specify--save-exactor manually editpackage.json. - To install it as a dev dependency (useful for build tools, testing frameworks, etc.), append
--save-dev:npm install --save-dev lodash@4.17.11 - If you want to pin the version strictly (no caret
^or tilde~inpackage.json), run:
This ensures that you always get the exact version specified, without minor or patch updates.npm install --save-exact lodash@4.17.11
Finding Versions:
- You can check available versions via the npm registry or using:
npm info <package-name> versions - Look for the one you want and reference it with the
@<version>syntax as shown above.
That’s it! You’ll now have that specific package version installed in your project.
Recommended Resource
CONTRIBUTOR
TechGrind