A lock file records the exact versions of every dependency installed in your project — including transitive dependencies. It ensures that everyone working on the project (and every deployment) uses identical package versions, preventing the 'it works on my machine' problem caused by version differences.
Lock files are boring but essential. They prevent a whole category of bugs caused by "but it works on my machine."
| Package Manager | Lock File |
|---|---|
| npm | package-lock.json |
| bun | bun.lockb |
| pnpm | pnpm-lock.yaml |
| yarn | yarn.lock |
Without a lock file:
package.json says: "react": "^19.0.0"
Developer A installs → gets React 19.0.0
Developer B installs next week → gets React 19.1.0
Production deploys → gets React 19.2.0
Same project, three different versions. Bugs happen.
With a lock file, everyone gets the exact same version.
Occasionally, lock files cause merge conflicts. The fix is usually:
node_modulesnpm install (or your package manager's install command)