'Npm install with two identical package.json results in different installed packages

I got error messages due to some package version incompatibilities. So I compared the git branch were the problem began with the branch before that.

The package.json files of those two commits are identical. When I go back to the earliest commit, I delete node_modules and run npm install. Then when I run npm list depth=0, (which shows the installed versions) the listed packages are the same as the ones listed in package.json, even those beginning with a caret , for instance "^3.1.2" is installed as 3.1.2.

However when I go to the later commit and do the same procedure, I see in the list from npm list that some packages have been updated from the specified version in package.json. Which is probably the cause of the error messages (being some typescript errors).

How can this happen?

See for instance these examples from the problematic commit:

package.json ------------------------- resulting package after npm install

"@nuxt/typescript":"2.8.1" - - - - - - - +-- @nuxt/[email protected] (this is fine)

"@nuxt/typescript-build": "^0.6.2" - - - +-- @nuxt/[email protected]

"@nuxt/typescript-runtime": "^0.4.2" - - +-- @nuxt/[email protected]

"@nuxtjs/eslint-module": "^1.1.0" - - - +-- @nuxtjs/[email protected]

"nuxt": "^2.12.2" - - - - - - - - - - - - - - +-- [email protected]

"eslint-plugin-prettier":"^3.1.2" - - - - +-- [email protected]

"prettier": "^2.0.4" - - - - - - - - - - - - +-- [email protected]

So in the problematic commit, npm install upgrades the packages having a caret before the version. In the earlier commit , it does not upgrade any package. And that's how I would like it to be, to get rid of the errors.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source