package-lock.json conflict — how to resolve
Quick Answer
# Simplest fix — delete and regenerate
rm package-lock.json
npm install
# This regenerates package-lock.json from package.json
When this happens
<<<<<<< HEAD
"lockfileVersion": 3,
=======
"lockfileVersion": 2,
>>>>>>> feature-branch
# (inside package-lock.json after git merge/rebase)
Two branches modified package-lock.json. It is auto-generated, so manual merging is error-prone. Deleting and regenerating is the safest approach.
Other causes & fixes
Prevent future conflicts with npm-merge-driver
# Install the merge driver
npx npm-merge-driver install --global
# It automatically handles package-lock.json conflicts
Keep one side of the conflict
# Accept your version (HEAD)
git checkout --ours package-lock.json
npm install # regenerate to ensure consistency
# Accept the incoming version
git checkout --theirs package-lock.json
npm install
Add package-lock.json to .gitattributes
# .gitattributes — use a custom merge strategy
package-lock.json merge=npm-merge-driver
Related