How to Fix an npm ERESOLVE error Without Breaking Your Project

How to Fix an npm ERESOLVE error Without Breaking Your Project How to Fix an npm ERESOLVE error Without Breaking Your Project

An install that worked yesterday can suddenly stop with an npm ERESOLVE error, a wall of package versions, and the message “unable to resolve dependency tree.” The fastest workaround may appear to be adding --force, but that can replace a visible installation failure with a harder runtime or build failure. A safer fix is to identify the incompatible peer dependency, select versions that satisfy the same contract, and update the lockfile deliberately.

This guide explains how npm builds a dependency tree, how to read its conflict report, and how to resolve common React, Angular, plugin, lockfile, and CI failures without destabilizing the project.

Why npm reports an ERESOLVE dependency conflict

A regular dependency is a package that a library needs and can usually install beneath itself. A peer dependency instead declares compatibility with a package expected to be supplied by the consuming application. React plugins, Angular tooling, ESLint plugins, and build-system extensions commonly use peers because they must work with the same framework instance as the application.

Suppose an application uses React 18 while an older plugin declares react: ^16.8 || ^17 as a peer. Installing a separate React 17 copy under that plugin would not necessarily make the integration safe. npm therefore attempts to place packages in a tree where the peer requirements can be satisfied together. If no valid placement exists, it stops with an npm peer dependency error.

Current npm releases retain the stricter peer-dependency behavior introduced with npm 7: peer dependencies are installed and validated rather than being treated merely as warnings. The authoritative npm package.json documentation recommends broad, compatible peer ranges for package authors, but applications still encounter packages with narrow or outdated ranges.

Read the error from the conflict outward

The useful lines in an ERESOLVE report usually identify four things:

  • The root project requirement: the version requested directly by your application.
  • The version npm found: often shown after Found:.
  • The conflicting package: the plugin or tool npm cannot place.
  • Its peer requirement: shown after peer or Could not resolve dependency.

A simplified React conflict might look like this:

Found: [email protected]
node_modules/react
  react@"^18.3.1" from the root project

Could not resolve dependency:
peer react@"^16.8 || ^17" from [email protected]

The problem is not that React failed to download. The root requests React 18, while [email protected] accepts only React 16 or 17. Focus on the first incompatible peer chain instead of every package listed later in the report. The complete diagnostic is also written to npm’s log directory, which is useful when terminal output is truncated.

Inspect the dependency tree before changing it

Use npm ls to find installed relationships

Run a targeted tree inspection rather than scanning the entire dependency graph:

npm ls react
npm ls older-widget
npm ls @angular/core
npm ls --all

npm ls marks invalid, missing, or extraneous packages and may exit with a nonzero status when it detects a broken tree. That result is diagnostic; it does not mean the command itself malfunctioned. In a workspace, run it from the relevant workspace or use npm’s workspace options so that you inspect the correct root.

Use npm explain to discover why a package exists

If a transitive dependency is unfamiliar, ask npm which chain introduced it:

npm explain older-widget
npm explain node_modules/react
npm explain @angular/compiler-cli

npm explain shows the dependency path and requirement that caused a package to be installed. See npm’s official command reference for supported forms.

Check available versions and peer ranges

Before upgrading or downgrading, inspect package metadata from the registry:

npm view older-widget versions --json
npm view older-widget@latest peerDependencies
npm view older-widget@3 peerDependencies
npm view react@18 version

Then inspect dependencies, devDependencies, peerDependencies, overrides, and workspace manifests in package.json. A package may be declared in more than one section, or an old override may be pinning a version that no longer fits.

A safe workflow to fix npm unable to resolve dependency tree

  1. Reproduce from a clean Git state. Record the Node and npm versions with node --version and npm --version. Confirm which registry and configuration are active with npm config list.
  2. Identify the smallest conflicting set. Extract the root package, incompatible package, found version, and required peer range from the ERESOLVE output.
  3. Confirm why each package is present. Use npm ls and npm explain. Check every workspace manifest if the repository is a monorepo.
  4. Inspect compatible releases. Use npm view, then review the package’s release notes or migration instructions before selecting a major version.
  5. Change one side of the conflict deliberately. Upgrade the plugin, downgrade the framework only when the application supports it, replace an abandoned package, or remove an unnecessary dependency.
  6. Run a normal npm install. Let npm update package-lock.json to reflect the intentional manifest change.
  7. Validate the result. Run npm ls, tests, type-checking, linting, production builds, and relevant application smoke tests.
  8. Test the locked installation. In a clean checkout or container, run npm ci. Commit package.json and package-lock.json together.

React, Angular, and plugin conflict examples

React plugin supports an older major version

If a project uses React 18 and a plugin accepts only React 17, first check whether a newer plugin release supports React 18:

npm view older-widget@latest peerDependencies
npm install older-widget@latest
npm ls react older-widget

If no compatible release exists, replacing the plugin is usually safer than forcing installation. Downgrading React may be reasonable only when the rest of the application and its libraries support that downgrade. Do not edit the plugin’s files inside node_modules; the change is temporary and unreproducible.

Angular packages are on different release lines

Angular packages and their build tooling are designed to follow coordinated compatibility requirements. For example, combining @angular/compiler-cli from one major release with @angular-devkit/build-angular from another can produce ERESOLVE. Inspect the peers and align the toolchain:

npm ls @angular/core @angular/compiler-cli @angular-devkit/build-angular
npm view @angular-devkit/build-angular@18 peerDependencies

Use Angular’s supported update path and migration tooling rather than independently bumping random @angular/* entries. Also verify TypeScript and Node.js requirements, because framework tooling may constrain those versions separately.

ESLint or build plugins lag behind their host

A plugin may declare a peer range for ESLint, Vite, webpack, or another host tool. Upgrade the plugin and its related configuration package together. If the plugin is transitive, upgrade the direct package that owns it. An npm overrides entry can control transitive versions, but it cannot make genuinely incompatible code compatible; use it only after confirming the replacement satisfies the consumer.

npm install, npm ci, legacy peer deps, and force

  • npm install: resolves dependencies from package.json, considers the existing lockfile, installs packages, and may update package-lock.json.
  • npm ci: performs a clean, frozen installation from the lockfile. It removes the existing node_modules, fails when the manifest and lockfile disagree, and does not rewrite the lockfile. It is generally the right choice for CI/CD.
  • --legacy-peer-deps: tells npm to ignore peer dependencies while constructing the tree, approximating older npm behavior. It can unblock installation but does not prove the packages work together.
  • --force: disables several npm safety protections and can permit conflicting peer dependencies at the project root. It is broader and riskier than legacy peer handling.

In the npm force vs legacy peer deps decision, neither flag resolves the underlying compatibility contract. Use either only as a short-lived, documented exception with thorough tests. If a lockfile was created using --legacy-peer-deps, npm ci may need the same setting. A project-level .npmrc makes that policy reproducible, but it also institutionalizes the bypass, so track its removal.

Handle a package-lock.json conflict safely

Deleting package-lock.json is not a harmless cache reset. It asks npm to resolve every allowed range again, potentially changing many transitive packages and hiding the original npm dependency conflict in a large diff.

Prefer editing the intended dependency in package.json and running npm install. Review the resulting lockfile diff for unexpected major changes, registry changes, or widespread churn. For a Git merge conflict, first resolve the manifests correctly, retain the lockfile from the appropriate branch as a starting point, and regenerate it with the project’s documented Node and npm versions.

A full regeneration is justified when the lockfile is corrupted or intentionally being rebuilt. Do it on a clean branch, pin the runtime and npm versions, remove node_modules and the lockfile, run npm install, execute the complete test suite, and verify a subsequent npm ci.

Reproducible npm install troubleshooting checklist

  • Capture Node, npm, operating system, registry, and relevant npm configuration.
  • Confirm the failing workspace and save the complete ERESOLVE report.
  • Identify the found version and the incompatible peer range.
  • Run targeted npm ls, npm explain, and npm view commands.
  • Inspect manifests, overrides, and the lockfile before deleting anything.
  • Select releases whose peer ranges overlap; upgrade dependent packages together.
  • Use a normal install to update the lockfile, then review the diff.
  • Run tests, linting, type checks, builds, and application smoke tests.
  • Run npm ci in a clean environment matching CI.
  • Commit manifest and lockfile changes together, with any temporary bypass documented.

Frequently asked questions

Why does npm install work locally while npm ci fails?

The local node_modules directory may contain stale packages, or npm install may have modified the tree without a committed lockfile update. npm ci requires exact agreement between package.json and package-lock.json. Different npm settings, runtime versions, registries, or missing workspace files can also explain an npm ci error.

Is –legacy-peer-deps safe?

It is safer than assuming a forced install proves compatibility, but it still ignores peer contracts. Use it only when testing demonstrates that the combination works and no compatible release is available. Record the reason and create a plan to remove it.

Should I delete node_modules when fixing ERESOLVE?

Removing node_modules can eliminate stale installed state, but it does not resolve incompatible version ranges. Preserve the lockfile initially and run npm ci for a clean reproduction. Delete the lockfile only when deliberate regeneration is warranted.

Can npm overrides fix a peer dependency error?

Overrides can replace a transitive package version, which is useful for controlled dependency management. They cannot change the actual compatibility of the consumer or host package. Confirm the overridden version satisfies required APIs, test it thoroughly, and revisit the override when upstream packages update.

The durable solution to an npm ERESOLVE error is rarely a stronger install flag. Treat the message as a compatibility report: trace the dependency path, align supported versions, update the lockfile intentionally, and prove the same tree works in both development and CI.

Leave a Reply

Your email address will not be published. Required fields are marked *