I had the exact same question as Do I need both package-lock.json and package.json? (tldr; "what's the difference between package.json
and package-lock.json
?") and found some really great answers in there. However it leaves me with a few other very similar-related questions that I don't see answered elsewhere.
For instance, what if package.json
and package-lock.json
conflict with one another? Say package.json
says to use some-lib-2.*
(any 2.x version of some-lib
) but package-lock.json
is configured to use some-lib-1.18.4
? Is there an error? Is preference given to either file as the "source of dependency truth"?
I like the idea of one file to manage my specific dependencies, and so I feel like I'm leaning towards:
- Not specifying libraries or version in
package.json
at all; and - Using
package-lock.json
to specify the exact versions of each module/library my project uses
Is this possible to do? If so are there any special configurations that I need to make? Do I track both files in version control, or is there ever any reasons why I would not want to track these in git/VCS?