# Lock file

> The Lock file in development ensures consistent dependency versions by tracking exact package resolutions.

## Should I commit package-lock.json to Git?

The file generated by a package manager, such as `package-lock.json`, that records the exact versions of all dependencies and their sub-dependencies. Committed to the repository, it makes every environment install identical versions and speeds up installs.

- Topic: Package Managers
- Type: file, concept

## Example

Wrong:

```bash
echo "package-lock.json" >> .gitignore
git add package.json
```

Right:

```bash
npm install zod
git add package.json package-lock.json
git commit -m "feat: add zod"
```

Committing the lock file with `package.json` makes every install resolve the same exact versions.

## Common mistakes

- Deleting the lock file to fix an install error and silently upgrading dozens of packages.
- Adding `package-lock.json` to `.gitignore`, so every machine installs different versions.

## Key points

- The lock file is committed and is not listed in `.gitignore`.
- Exactly one lock file exists, matching the package manager the project uses.
- CI installs strictly from the lock file with `npm ci` or a frozen-lockfile flag.
- Lock file conflicts are fixed by rerunning the install, not by deleting the file.

## Interview questions

### How do I resolve merge conflicts in package-lock.json?

Resolve the conflicts in `package.json` first, then run `npm install`. npm can merge a conflicted lock file and rewrites it in a clean state.

### Should libraries commit a lock file?

Yes, for reproducible development and CI. The lock file is not published, so users still resolve versions from your `package.json` ranges.

### What is the difference between package-lock.json and yarn.lock?

They do the same job for different tools. npm reads `package-lock.json`, Yarn reads `yarn.lock`, pnpm reads `pnpm-lock.yaml`.

## Related cards

- [npm ci](https://wonderium.dev/processes/npm-ci.md)
- [package.json](https://wonderium.dev/processes/package-json.md)
- [SemVer](https://wonderium.dev/processes/semver.md)
- [Package Managers](https://wonderium.dev/processes/package-managers.md)
- [.gitignore](https://wonderium.dev/processes/gitignore.md)

---

- Level: [Processes](https://wonderium.dev/processes.md)
- HTML version: https://wonderium.dev/processes/lock-file
- Last updated: 2026-11-25
