I am learning about the differences between package.json and package-lock.json
I been experimenting on a package with only one dependency called chance
I first installed it via npm i chance@1.0.0 and the package.json has "chance": "^1.0.0" and package-lock.json has "version": "1.0.0".
Because I wanted to see the effect that the lock file has on the version, I went ahead and deleted package-lock.json and node_modules, I ran npm install, the version of chance stays the same in package.json, which is "chance": "^1.0.0". In the newly created lock file, the version of chance became "chance": {"version": "1.1.8",, so it updated itself.
I then deleted package-lock.json and node_modules again and ran npm update, the results seemed to be the same with the previous experiment – in package.json I have "^1.0.0" in package.json and "1.1.8" in package-lock.json
My questions are:
- in either case, with
"^1.0.0"inpackage.jsonand"1.1.8"inpackage-lock.json, which version of the dependency am I actually using in my project, I guess it is1.1.8right? so by merely looking at the versions inpackage.jsonis not enough to determine the exact version of the dependencies used in a project? - When does running
npm installchange the lock file? I know that if we delete the lock file, it will generate a new one with the newest versions in the allowable ranges frompackage.json. But are there any cases wherenpm installwould change the lock file even if I didn't delete the lock file?