Lockfile formats
Bun supports two lockfile formats:Binary lockfile (bun.lockb)
Default format. Fast to read/write, compact size.Text lockfile (bun.lock)
Human-readable format, better for version control diffs.Choosing a format
Binary lockfile (default)
Best for:- Large projects with many dependencies
- Faster CI/CD pipelines
- Private projects with less merge conflicts
- 3x faster to parse
- 3x smaller file size
- Less disk I/O
- Not human-readable
- Binary diffs in version control
Text lockfile
Best for:- Open source projects
- Projects requiring human review of dependency changes
- Better git diffs
- Human-readable
- Reviewable diffs
- Easy to debug
- Larger file size
- Slower parsing
Configuration
Use text lockfile
Via bunfig.toml
Via CLI flag
Generate text lockfile on next install:Convert formats
Convert binary to text:bunfig.toml:
Lockfile behavior
Automatic generation
Bun automatically creates/updates the lockfile:Lockfile updates
The lockfile updates when:- Installing new packages
- Removing packages
- Updating package versions
- Changing version ranges in
package.json
Frozen lockfile
Prevent lockfile updates (useful in CI):package.json.
Via bunfig.toml
No lockfile
Install without creating/updating lockfile:Lockfile structure
Binary lockfile
Binary format (not human-readable):Text lockfile format
Lockfile commands
View lockfile hash
View hash string
Print stored hash
Migration
From other package managers
Migrate existing lockfiles:package-lock.json(npm)yarn.lock(Yarn)pnpm-lock.yaml(pnpm)
Version control
Commit lockfile
Always commit your lockfile:Ignore lockfile (not recommended)
If you must ignore lockfile:CI/CD
GitHub Actions
Cache and use lockfile:GitLab CI
Troubleshooting
Lockfile out of sync
If lockfile doesn’t matchpackage.json:
Merge conflicts
For binary lockfile conflicts:Corrupted lockfile
If lockfile is corrupted:Different machines
If lockfile differs between machines:- Ensure same Bun version:
- Use same registry:
- Regenerate lockfile:
Custom lockfile path
Set lockfile path
Save lockfile to different location
Workspaces
In workspace projects, use a single root lockfile:Performance
Binary lockfile
- Read time: ~5-10ms for 1000 packages
- Write time: ~10-20ms for 1000 packages
- File size: ~100-200KB for 1000 packages
Text lockfile
- Read time: ~15-30ms for 1000 packages
- Write time: ~30-60ms for 1000 packages
- File size: ~300-600KB for 1000 packages
Best practices
Always commit lockfile
Use frozen lockfile in CI
Review lockfile changes
For text lockfiles:- Unexpected version changes
- New dependencies
- Removed dependencies