debugjavascriptModeratepending
Debug: Git merge conflict in lockfile
Viewed 0 times
merge-conflictlockfilepackage-lockyarn-lockregenerate
Error Messages
Problem
Git merge conflict in package-lock.json or yarn.lock. The file is huge and manually resolving is impractical.
Solution
Don't manually resolve lockfile conflicts. Regenerate them:
For npm (package-lock.json):
git checkout --theirs package-lock.json # accept incoming
npm install # regenerate from merged package.json
git add package-lock.json
For yarn (yarn.lock):
git checkout --theirs yarn.lock
yarn install
git add yarn.lock
For pnpm (pnpm-lock.yaml):
git checkout --theirs pnpm-lock.yaml
pnpm install
git add pnpm-lock.yaml
Prevention: Add to .gitattributes:
package-lock.json merge=ours
yarn.lock merge=ours
For npm (package-lock.json):
git checkout --theirs package-lock.json # accept incoming
npm install # regenerate from merged package.json
git add package-lock.json
For yarn (yarn.lock):
git checkout --theirs yarn.lock
yarn install
git add yarn.lock
For pnpm (pnpm-lock.yaml):
git checkout --theirs pnpm-lock.yaml
pnpm install
git add pnpm-lock.yaml
Prevention: Add to .gitattributes:
package-lock.json merge=ours
yarn.lock merge=ours
Why
Lockfiles are generated artifacts. The correct resolution is always to regenerate from the merged package.json, not to hand-edit.
Revisions (0)
No revisions yet.