Skip to main content
⚡ OpenDevDocs
Package Managers
programmingpackage-managersCore ConceptIntermediate

Lock Files & Deterministic Builds

Complete guide to package-lock.json, pnpm-lock.yaml, yarn.lock, resolving merge conflicts, and running reproducible CI builds with npm ci.

Verified: 2026-09-30
Tested on:npm 10.x, pnpm 9.x
Platforms:
linuxmacoswindows
#lockfiles#npm#pnpm#ci-cd

A Lock File (package-lock.json, pnpm-lock.yaml, yarn.lock) records the exact version, integrity hash, and download URL of every direct and transitive dependency installed in your project.


Why Lock Files are Mandatory

Without a lock file, if your package.json contains "express": "^4.21.0":

  • Developer A installs on Monday and gets Express 4.21.0.
  • Express releases 4.21.1 on Tuesday.
  • Developer B installs on Wednesday and gets Express 4.21.1.
  • Production builds on Thursday may fail due to unexpected upstream patch changes.

Lock files guarantee 100% deterministic builds: anyone cloning the repository gets the exact same byte-for-byte dependency tree.


Lock File Comparison

ToolLock FileFormatCharacteristics
npmpackage-lock.jsonJSONLarge, comprehensive nested tree format
pnpmpnpm-lock.yamlYAMLCompact, human-readable, store references
Yarnyarn.lockCustom YAML-likeFlat dependency resolution map
Bunbun.lockb / bun.lockBinary or textHigh-performance lock format

npm install vs npm ci

Featurenpm installnpm ci (Clean Install)
Lock File ModificationCan modify package-lock.jsonNever modifies package-lock.json
Existing node_modulesModifies incrementallyDeletes ./node_modules entirely first
SpeedSlowerSignificantly faster in CI pipelines
Mismatch HandlingSyncs lock file to package.jsonFails the build immediately

Running in CI/CD Pipelines:

# npm
npm ci

# pnpm
pnpm install --frozen-lockfile

Resolving Lock File Merge Conflicts

When two Git branches add different dependencies, Git may flag a conflict inside the lock file.

Never manually edit a 5,000-line lock file in your text editor. Follow this safe workflow:

# 1. Resolve conflicts in package.json manually
git checkout --theirs package.json # or edit by hand

# 2. Regenerate the lock file automatically
npm install
# or for pnpm:
pnpm install

# 3. Stage the cleanly regenerated lock file
git add package.json package-lock.json
git commit -m "Resolve dependency conflicts and regenerate lockfile"

On this page