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?
3 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/
-
13Also, for both npm and yarn
-E
is the short form of--save-exact
/--exact
Jan 14, 2019 at 14:42 -
-
1Is there any way to make this behavior default across all installations with
npm
? Jan 26, 2022 at 18:49 -
2yes, there is:
npm config set save-exact=true
or you can addsave-exact=true
to your .npmrc manually– TomRaaffJul 15, 2022 at 11:48
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.
-
5Please note that there is still one issue with all subdependencies. Even if you specify strict versions for direct dependencies, the is no guarantee that those in turn will not trigger the installation of something new when it will be released. Dec 28, 2016 at 17:12
-
I can't believe this is the only solution. It's very important for those creating packages to test with the lowest possible number. I'm considering creating a separate
package-min.json
file and using that as thepackage.json
in CI Aug 15, 2019 at 9:56
You can also open package.json
and change value for the package you want to remain exact. From "vue": "^2.6.10"
to "vue": "2.6.10"
. Notice the lack of ^
sign in front of the version number.
package.json
? there is a modifier for fixed version.package.json
had versions specified as^version
. I just assumed this how to versions. Will remove the^
modifier. Thanks!