Demo, all content is generated
Question

package-lock.json merge conflict every single time I pull

Solved · 284 views · asked by coop_builds · edited

I build in Bolt and push to GitHub, and a friend fixes stuff locally in VS Code. Every time I pull his changes into my local copy I get a conflict in package-lock.json, thousands of lines with <<<<<<< in them. Last time I just deleted the file and it broke the build on Netlify for a day.

What's the right way to handle this?

What I’ve tried

Deleted package-lock.json (broke the build), tried accepting 'both changes' in VS Code (made an invalid JSON file).

Comment
Do you and your friend use the same npm version? ximena_c · edited

2 answers

Marked as helpful by the asker
ximena_c · edited

Never hand-merge a lockfile. Resolve package.json by hand (that one is small and readable), then let npm rebuild the lock:

# during the merge conflict
git checkout --theirs package-lock.json   # take the incoming lock as a base
npm install                               # adds whatever your package.json needs on top
git add package.json package-lock.json
git commit

Starting from one side's lockfile (instead of deleting it) keeps all the other versions pinned, so you don't silently upgrade 400 packages like last time.

Root cause is usually two npm versions writing different lockfile formats. Check npm -v on both machines and agree on one, or pin it with "packageManager": "npm@10.8.2".

Comment
Good answer. --theirs/--ours flip meaning during a rebase, so if you use pull --rebase, double check which side you got. ollie_dev · edited
Friend was on npm 8, I was on 10. We both updated. Next pull: no conflict at all. coop_builds · edited
sanne_dev · edited

Also, if Bolt and your friend both add packages in the same week, one of you will still conflict. Agree who adds dependencies, it's a two-person team so that's just a message.

Comment