I just recently upgraded to npm@5. I now have a package-lock.json file with everything from package.json. I would expect that, when I run npm install
that the dependency versions would be pulled from the lock file to determine what should be installed in my node_modules directory. What's strange is that it actually ends up modifying and rewriting my package-lock.json file.
For example, the lock file had typescript specified to be at version 2.1.6. Then, after the npm install
command, the version was changed to 2.4.1. That seems to defeat the whole purpose of a lock file.
What am I missing? How do I get npm to actually respect my lock file?
You probably have something like:
in your
package.json
which npm updates to the latest minor version, in your case being2.4.1
More on
package-lock.json
:package-lock.json is automatically generated for any operations where npm modifies either the node_modules tree, or package.json. It describes the exact tree that was generated, such that subsequent installs are able to generate identical trees, regardless of intermediate dependency updates.
This file is intended to be committed into source repositories, and serves various purposes:
https://docs.npmjs.com/files/package-lock.json
There is an open issue for this on their github page: https://github.com/npm/npm/issues/18712
This issue is most severe when developers are using different operating systems.
EDIT: the name "lock" is a tricky one, its NPM trying to catch up with Yarn. It isn't a locked file whatsoever.
package.json
is a user-fixed file, that once "installed" will generate node_modules folder tree and that tree will then be written inpackage-lock.json
. So you see, its the other way around - dependency versions will be pulled frompackage.json
as always, andpackage-lock.json
should be calledpackage-tree.json
(hope this made my answer clearer, after so many downvotes)
A simplistic answer:
package.json
have your dependencies as usual, whilepackage-lock.json
is "an exact, and more importantly reproducible node_modules tree" (taken from npm docs itself).As for the tricky name, its NPM trying to catch up with Yarn.
Use the
npm ci
command instead ofnpm install
."ci" stands for "clean install". It will install the project dependencies based on the package-lock.json file instead of the lenient package.json file dependencies.
It will produce identical builds to your other team mates and it is also much faster.