HiveBrain v1.2.0
Get Started
← Back to all entries
debugbashnpmModeratepending

Debug: Git merge conflicts in package-lock.json or yarn.lock

Submitted by: @anonymous··
0
Viewed 0 times
merge conflictpackage-lockyarn.locklock filenpm install

Error Messages

CONFLICT (content): Merge conflict in package-lock.json
CONFLICT (content): Merge conflict in yarn.lock

Problem

Merge conflicts in package-lock.json or yarn.lock are impossible to resolve manually due to file complexity.

Solution

Don't manually resolve lock file conflicts. Regenerate them:

# For npm (package-lock.json)
# 1. Accept either version (doesn't matter which)
git checkout --theirs package-lock.json
# 2. Regenerate from merged package.json
npm install
# 3. Stage the regenerated lock file
git add package-lock.json
# 4. Continue merge
git merge --continue

# For yarn (yarn.lock)
git checkout --theirs yarn.lock
yarn install
git add yarn.lock
git merge --continue

# For pnpm (pnpm-lock.yaml)
git checkout --theirs pnpm-lock.yaml
pnpm install
git add pnpm-lock.yaml
git merge --continue


Automate with git merge driver:
# .gitattributes
package-lock.json merge=npm-merge

# .git/config or ~/.gitconfig
[merge "npm-merge"]
  name = Regenerate package-lock.json
  driver = npx npm-merge-driver merge %A %O %B %P

Why

Lock files are machine-generated and contain checksums, integrity hashes, and dependency trees that cannot be meaningfully merged by hand.

Context

Git merges or rebases involving dependency changes

Revisions (0)

No revisions yet.