npm ci fails: reproduce the resolver configuration
Reproduce the resolver that created the lockfile before deciding whether the dependency graph should change.
Quick answer
When npm ci rejects a lockfile that installs elsewhere, preserve the manifests and compare effective configuration, the invocation root and exact Node/npm versions. Tree-shaping flags must match lock generation. A project npmrc can be overridden by environment or command options. Reproduce an accepted baseline separately from removing a legacy peer exception and testing the compatible dependency graph.
On this page
When npm ci fails against a lockfile that installs elsewhere, compare the effective resolver configuration before regenerating dependencies. The lockfile records a dependency tree, while npm also reads command-line options, environment variables and configuration files. Flags that affected the original tree must be reconciled with the clean install. Reproducing an old exception and removing that exception are separate changes. [1][2][3][4]
Scenario: a fictional invoice frontend has a committed package manifest and lockfile. A developer generated them while using legacy-peer-deps; CI runs with different effective settings and rejects the install. Another job succeeds but cannot find a build tool because it omits development dependencies. These failures share a repository but require different repairs.
Keep the invoice frontend's manifests unchanged while comparing resolver settings. Review the compatibility change separately. It does not assume that every npm failure is a peer-dependency problem. Registry access, platform-specific packages, lifecycle scripts and actual lockfile defects remain distinct branches.
Why does the same lockfile behave differently in CI?#
The lockfile is an important input rather than the whole execution environment. npm documents that npm ci requires an existing lock and refuses to rewrite mismatched package manifests. It also explicitly warns that tree-shaping flags such as legacy-peer-deps and install-links must match the conditions under which the lockfile was created. [1]
Start by saving the exact error and the stage at which it occurs. A dependency-resolution rejection happens before the application's tests can establish compatibility. A registry authentication error belongs to access configuration. A build command missing after a successful install may be an omission policy. A lifecycle script failure can occur after a valid dependency graph has already been selected.
Save the failing lockfile before testing a new resolution, so the rejected graph remains reproducible. A new resolution changes the graph and removes the original comparison point. Preserve the original manifests and install log so you can distinguish a successful reproduction from a different graph that happens to install.
Check which lockfile actually governs the root project. npm documents that a root npm-shrinkwrap.json takes precedence when both it and package-lock.json are present. Comparing a package lock that the command does not use produces a convincing but irrelevant fingerprint. Also confirm the working directory and workspace context. [3]
Scenario: the invoice frontend runs locally from its project root, but the failing job changes into a nested directory. Before touching dependencies, the operator compares the root reported by npm and the paths of the manifests used in each environment. The repair might be a job working-directory correction rather than any resolver flag.
Which resolver inputs should you compare?#
Compare selected effective values, not an unrestricted dump of every configuration source. npm reads configuration from multiple places and resolves it by priority. A committed project .npmrc is useful evidence, but a higher-priority environment value or command-line flag can still change the result. [2][4]
This small diagnostic command list is intended to run from the same project root and job step as the install. Save its output beside the manifest identifiers. It deliberately avoids printing all configuration or environment variables, which can include registry credentials and unrelated secrets.
node --version
npm --version
npm prefix
npm config get legacy-peer-deps
npm config get install-links
npm config get install-strategy
npm config get omit
npm config get include
npm config get ignore-scriptsThe config get command prints selected effective settings. Check explicit flags on the actual install command separately: a diagnostic command without those flags cannot report the effect of flags that only appear on a later command. If the job runs inside a container, capture the values inside that container rather than on the host that launched it. [5]
For the fictional frontend, the useful comparison record looks like this. The values are example observations to collect, not results measured from a real project.
| Input | Developer environment | Failing CI environment | Meaning |
|---|---|---|---|
| Manifests | Recorded content hashes | Same hashes | Graph inputs are comparable |
| Node and npm | Recorded exact versions | Recorded exact versions | Toolchain drift is visible |
| Project root | Invoice frontend root | Verify actual job root | Project config can depend on invocation context |
| Legacy peer setting | Enabled for old lock generation | Disabled | Candidate explanation for resolver rejection |
| Omit/include policy | Build tools present | Development dependencies omitted | Separate explanation for missing build commands |
| Lifecycle policy | Known project policy | Known job policy | Install execution differs from graph selection |
Record only configuration relevant to the failure. If a native dependency is involved, operating system, CPU architecture and the matching toolchain become relevant too. If registry access fails, compare the intended registry and authentication scope through the project's normal secret-handling process. Do not attach tokens or a raw .npmrc containing credentials to an incident record.
The difference between legacy-peer-deps and omit=peer is especially easy to miss. The former ignores peer contracts while building the tree; the latter still plans a tree with peer relationships while omitting those packages from disk. They are not interchangeable repairs. npm's configuration documentation makes that distinction explicit and recommends against relying on the legacy option as a general default. [4]
Likewise, omit=dev changes which packages are physically installed. A build step that needs a development dependency must have it available in the stage that performs the build. Deciding what belongs in the final runtime image is a later boundary. Keeping those stages distinct is the subject of our multi-stage build guide. [1]
How do you restore a reproducible baseline?#
First decide whether the observed legacy setting was intentional. Ask the dependency owner or inspect the change that introduced it. If it is an acknowledged temporary exception, reproduce it as a project-scoped setting and retain an explicit removal task. If it was accidental or conceals an unsupported combination, move directly to compatibility work rather than silently standardizing it.
For the temporary-parity branch, npm's documented approach is a project .npmrc. The example below applies to the fictional frontend's existing legacy lockfile. It is not a recommendation to enable this option in every repository. [1][2]
# Project .npmrc for an explicitly accepted temporary exception
legacy-peer-deps=trueRun the clean install from a disposable checkout or container using the recorded Node/npm toolchain and effective settings. npm ci removes an existing node_modules before installing, so a fresh invocation already has a specific cleanup contract. Clearing caches or deleting unrelated volumes is not the first diagnostic step. [1]
# Initial graph/install diagnosis only; lifecycle work is intentionally skipped.
npm ci --ignore-scripts
# Then follow the project's reviewed lifecycle policy and run its normal checks.
npm ci
npm test
npm run buildThe script-suppressed install is a diagnostic branch, not proof that the project is ready to run. Some dependencies require generated files or native build steps. The normal install must follow the project's approved script policy, and the relevant tests must exercise the affected integration. A package graph that installs is weaker evidence than an application that works with that graph.
Now demonstrate that the project file is actually governing the setting. In an isolated copy, compare the selected value with and without an overriding environment variable. This exercise changes only the temporary command environment and prints a non-secret boolean.
npm config get legacy-peer-deps
npm_config_legacy_peer_deps=false npm config get legacy-peer-depsScenario: the first command prints true from the temporary project exception, while the second prints false. That difference explains why committing .npmrc alone is not sufficient evidence of parity. Inspect the CI variables and actual command options before concluding that a committed configuration is being applied. Do not remove a job setting whose owner or purpose is unknown merely because it differs.
Keep the successful baseline tied to the manifests and selected settings. In the operator's record, store exact manifest hashes, runtime versions, invocation root, relevant options, exit status and the follow-up test results. This is a reproduction record, not a claim that those inputs eliminate every operating-system or registry difference.
When should you remove the peer exception?#
Remove it when the dependency graph has been changed to satisfy the intended peer relationships and the application checks support that change. Treat this as a separate dependency update, with its own diff and acceptance evidence. Otherwise the team can mistake “we reproduced the old tree” for “we repaired the unsupported combination.” [4]
Read the resolver's conflict report and the affected packages' own compatibility documentation. Identify which package declares the peer, which version is present and which supported versions can work together. Choose an upgrade, downgrade, replacement or a documented maintainer-supported path. Broad force flags do not explain compatibility and can remove protections beyond the specific conflict.
In the fictional frontend, the operator first recovers the legacy baseline so the failure is understood. The next change replaces an incompatible plugin with a compatible release, removes the project exception and regenerates the lock using the chosen toolchain. The dependency diff and the application tests then answer a different question: does the revised graph work without ignored peer contracts?
Use npm ls to inspect the installed graph and the named packages involved. npm documents that it reports missing, invalid and extraneous packages. Interpret its output in light of the chosen omission policy: a diagnostic graph report is useful evidence, but it does not run application code or prove that a browser integration behaves correctly. [6]
npm ls --all
# Narrow the report to the actual packages named by your conflict.
npm ls your-host-package your-plugin-packageThe final line contains placeholders for the real package names. Do not add those literal names as dependencies. Capture the narrowed report and the tests that exercise the host/plugin boundary, rather than relying on a large dependency listing nobody reviews.
If matching configuration still fails, retain that result. The problem can be an inconsistent manifest, a lockfile produced incorrectly, a toolchain difference or an npm defect. A useful upstream reproduction includes a minimal project, exact versions, selected configuration and the error, with credentials and private dependency details removed. Repeatedly generating new locks until one passes loses that evidence.
What evidence makes the build repeatable?#
Record the clean install, selected resolver values and the host/plugin checks together. It should also distinguish the build environment from the final runtime environment and identify the process for removing any temporary peer exception.
If the clean install succeeds but the service still starts with an incomplete prerequisite, inspect the startup contract. Our Compose readiness guide distinguishes a healthy dependency from a completed migration. A successful resolver step cannot prove that the rest of the delivery workflow finished.
An isolated configuration fixture on npm 10.2.3 checked the project setting, environment override, explicit flag override and install-links value. No dependency installation, lifecycle script or host/plugin compatibility test was run for this article. The cited reference pages are npm CLI version 11 documentation as read on 7 November 2026. [1][2][3][4][5][6] Record and reproduce your project's actual toolchain, consult its matching documentation when behavior differs, and review a toolchain migration separately from the dependency repair.
What else should you check?#
- Should I delete package-lock.json when npm ci fails?
- Preserve the failing manifests and error while identifying the failure stage. Regenerating the lock changes the graph and removes the original comparison point. If the manifests are inconsistent, repair them deliberately with the chosen toolchain and review the resulting dependency diff. [1][3]
- Is legacy-peer-deps the same as omit=peer?
- No. The legacy option ignores peer dependency contracts while designing the tree. Omit peer still plans those relationships while leaving packages off disk. npm advises against relying on legacy resolution as a general default; choose compatibility work or an explicitly owned exception. [4]
- Does a committed npmrc guarantee matching CI settings?
- No. npm also reads environment variables and command-line options. Compare selected effective values in the actual install context and inspect flags on that command. A diagnostic command without the install's explicit flags cannot demonstrate their later effect. [2][4][5]
- Does a successful clean install establish application compatibility?
- It establishes less than a working application. Run the project's reviewed lifecycle steps and checks that exercise the affected dependency boundary. npm ls can report graph problems, but neither an install nor a dependency listing runs those integration behaviors. [1][6]