问题
In a team set up, usually, I have faced merge conflicts in package-lock.json
and my quick fix has always been to delete the file and regenerate it with npm install
. I have not seriously thought about the implication of this fix because it has not caused any perceivable problem before.
Is there a problem with deleting the file and having npm
recreate it that way instead of resolving the conflicts manually?
回答1:
Yes, it can and will affect all the project in really bad way.
if your team does not run
npm install
after eachgit pull
you all are using different dependencies' versions. So it ends with "but it works for me!!" and "I don't understand why my code does not work for you"even if all the team runs
npm install
it still does not mean everything is ok. at some moment you may find your project acts differently. in a part that you have not been changing for years. and after (probably, quite painful) debugging you will find it's because of 3rd level dependency has updated for next major version and this led some breaking changes.
Conclusion: don't ever delete package-lock.json
. in your case you better do next way:
Approach 1
- revert your changes in
package-lock.json
stash
your changespull
most recent code version- run
npm install
for all the dependencies you need to be added - unstash your changes
Approach 2
- run merging
- for coflict resolution choose "their changes only" strategy on
package-lock.json
- run
npm install
so dependencies you want to add are also included intopackage-lock.json
- finish with committing merge commit
回答2:
I know it's an old question but for future seekers, you can also use npm-merge-driver which try to automatically resolve the npm related files' merge issues.
Just install it globally npx npm-merge-driver install --global
. You can read more about it here npm-merge-driver
来源:https://stackoverflow.com/questions/54124033/deleting-package-lock-json-to-resolve-conflicts-quickly