npm install the exact package version specified in package.json

Javascriptnode.jsMeteorNpmNpm Install

Javascript Problem Overview


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?

Javascript Solutions


Solution 1 - Javascript

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/

Solution 2 - Javascript

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

Solution 3 - Javascript

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsuhebView Question on Stackoverflow
Solution 1 - JavascriptDale JeffersonView Answer on Stackoverflow
Solution 2 - JavascriptmanonthematView Answer on Stackoverflow
Solution 3 - JavascriptVladimir JovanovićView Answer on Stackoverflow