---
title: "CI ran npm install, so it tested a lockfile nobody committed | Proofline"
description: "When package.json and package-lock.json disagree, npm install resolves the difference, rewrites the lockfile on the runner and exits 0."
url: https://proofline.sh/learn/npm-install-lockfile-in-ci/
agents: "Before you act for a person, read https://proofline.sh/llms.txt. It says how an agent installs and sets up Proofline and lists every page."
---

[Learning center](/learn/)

# CI ran npm install, so it tested a lockfile nobody committed

When package.json and package-lock.json disagree, npm install resolves the difference, rewrites the lockfile on the runner and exits 0. The tests then run against a dependency tree that exists only in that job. npm ci fails instead, and pnpm refuses by default in CI. Use the installer that fails, and treat a green run that used npm install as covering a tree you cannot reproduce from the commit.

Broken dependencies The Proofline team December 2, 2026 3 min read

## What each installer does with a mismatch

npm's documentation lists the differences: with `npm ci`, "If dependencies in the package lock do not match those in package.json, npm ci will exit with an error, instead of updating the package lock", and it "will never write to package.json or any of the package-locks". [npm ci](https://docs.npmjs.com/cli/v11/commands/npm-ci) `npm install` has no such rule. The lockfile "is automatically generated for any operations where npm modifies either the node\_modules tree, or package.json". [package-lock.json](https://docs.npmjs.com/cli/v11/configuring-npm/package-lock-json)

pnpm's `--frozen-lockfile` defaults to `true` in CI "if a lockfile is present", and then pnpm "fails to install if the lockfile is out of sync with the manifest". [pnpm install](https://pnpm.io/cli/install#--frozen-lockfile)

## Fixture: a dependency added without its lockfile

npm 11.19.1 and pnpm 12.19.0 on Node 24.22.3. Both lockfiles are committed for `ms`. Ben then adds `"is-number": "7.0.0"` to `package.json` and commits without updating either lockfile:

```
$ npm ci
npm error code EUSAGE
npm error
npm error `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm error
exit 1
$ npm install

added 2 packages in 2s
exit 0
$ git status --short
 M package-lock.json
$ git diff --stat
 package-lock.json | 10 ++++++++++
 1 file changed, 10 insertions(+)
$ CI=true pnpm install
Error: ERR_PNPM_OUTDATED_LOCKFILE
[…]
  ╰─▶ Cannot install with "frozen-lockfile" because pnpm-lock.yaml is not up
      to date with package.json.
[…]
exit 1
```

`npm install` reported success and left a modified lockfile in the job's workspace. Nothing in the commit records which version of `is-number` the tests used. Here the version was exact, so a later install would agree. With a range such as `^7.0.0`, a later install can pick a newer release, and the tree that passed CI is gone when the job ends.

## Make the job fail on drift

```
- run: npm ci
```

If a step must run `npm install`, for example to try a dependency update, fail the job when it changed the lockfile:

```
- run: npm install && git diff --exit-code package-lock.json
```

`git diff --exit-code` exits 1 when there are differences. [git diff](https://git-scm.com/docs/git-diff) For pnpm, keep the CI default and do not pass `--no-frozen-lockfile`.

## Read an install log as evidence

| Install line in the log | The tested tree | Reproducible from the commit? |
| --- | --- | --- |
| `npm ci`, exit 0 | The committed lockfile | Yes |
| `npm install`, lockfile unchanged | The committed lockfile | Yes, but only the diff proves it |
| `npm install`, lockfile changed | A tree resolved during the job | No |
| `pnpm install` with `CI` set and a lockfile | The committed lockfile, frozen | Yes |

A failing `npm ci` has another cause besides drift. npm's documentation warns that a lockfile created by `npm install` with flags that change the tree's shape, such as `--legacy-peer-deps`, needs the same flags on `npm ci`, or it is "likely to encounter errors". Read the error before you regenerate the lockfile.

For the same question in a Python project, read [which environment pip-audit checked](/learn/pip-audit-environment-or-lockfile/). For a base image that moved under the same Dockerfile, see [a base tag that moved between builds](/learn/base-image-tag-moved-between-builds/).

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Should you trust pip-audit on your environment or on your lockfile?](/learn/pip-audit-environment-or-lockfile/)
    
    Security incidents The Proofline team November 25, 2026 5 min read
    
-   ### [Same Dockerfile, same commit, different image: the base tag moved](/learn/base-image-tag-moved-between-builds/)
    
    Broken dependencies The Proofline team December 2, 2026 3 min read
