Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install the exact package version specified in package.json

Currently, If I run npm install, it installs the updated version of already installed packages. How can I install the exact version as specified in the package.json file?

like image 289
suheb Avatar asked Dec 06 '16 19:12

suheb


People also ask

How do I install the exact version of npm?

For npm install specific version, use npm install [package-name]@[version-number]. Use npm view [package-name] version to know the specific latest version of a package available on the npm registry. Use npm list [package-name] to know the specific latest version of an installed package.

Can you specify node version in package json?

Use the engines keyword in the package. json file to specify the Node. js version that you want your application to use. You can also specify a version range using npm notation.

How do I update npm packages to a specific version?

To update a specific package, we need to run the npm update command followed by the package name. Sometimes, you want to update a package to the specific version in such cases you need to use npm install command by specifying a version number after the package name.


2 Answers

By default npm installs packages using ^ which means any version in the same major range, you can switch this behaviour by using --save-exact

// npm npm install --save --save-exact react  // yarn yarn add --exact react 

I created a blog post about this if anyone is looking for this in the future.

https://www.dalejefferson.com/articles/2018-02-04-how-to-save-exact-npm-package-versions/

like image 124
Dale Jefferson Avatar answered Oct 25 '22 18:10

Dale Jefferson


That behavior is really driven by the one specifying the versions in the package.json. If the version number looks like "1.0.0", without any other symbols, the exact version (1.0.0) should be installed.

So what you could do is simply modify the package.json and run a npm install then. Be sure to clear out the node_modules directory before you do that.

https://docs.npmjs.com/files/package.json#dependencies

like image 32
manonthemat Avatar answered Oct 25 '22 17:10

manonthemat