published fresh until

npm install fails with ERESOLVE: what do I try before --force?

Summary When npm install fails with ERESOLVE, identify the peer dependency conflict, then upgrade or replace the package or pin a nested version with overrides. --legacy-peer-deps skips peer checks and can hide the risk; npm 7+ installs peers by default.

Not for npm audit vulnerabilities, lockfile merge conflicts

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

You (or your agent) add a package and npm install stops with ERESOLVE unable to resolve dependency tree. The quick fixes people paste are --force or --legacy-peer-deps. They can bypass peer conflicts, but they decide nothing about whether the packages actually work together.

What the sources say

  • A Stack Overflow answer explains the cause: npm 7 and later install peerDependencies automatically, and a package that names a specific host version (for example React 17 or 18) conflicts with a different version you already have. --legacy-peer-deps restores the old npm 3 to 6 behaviour of ignoring peer dependencies when building the tree, at the risk of breaking changes.
  • The npm package.json docs say peer ranges should be as broad as possible, and describe overrides: a root package.json key that pins a package, or a nested one ("bar": { "foo": "1.0.0" }), anywhere in the tree. Only the root file counts, and overriding a direct dependency needs the override and the dependency to share the exact same spec (otherwise EOVERRIDE).
  • The npm install docs describe strict-peer-deps: by default npm resolves deep peer conflicts using the nearest non-peer spec and prints a warning; with the flag the warning is a failure.

How to describe it to your agent

npm install fails with ERESOLVE. Do not use --force or --legacy-peer-deps yet. Paste the conflict lines, name which package's peer range excludes which installed version, then list options: a newer release of that package, a maintained replacement, or an overrides entry. Tell me what could break with each before changing package.json.

Mistakes to check

  • Using --force and committing a lockfile built from it, so teammates and CI hit the same wall or a different one.
  • Adding legacy-peer-deps=true to .npmrc for the whole project to silence one package.
  • Writing an overrides entry for a direct dependency with a different spec (fails with EOVERRIDE).
  • Treating an old unmaintained package with a React 16 peer range as fine on React 19 because it installed.

Limits

Built from the npm docs and a Stack Overflow answer; I did not reproduce the errors. Behaviour differs between npm versions, so check yours with npm -v.

Started from a post by @Stack Overflow answer plus npm docs, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# npm install fails with ERESOLVE: what do I try before --force?
Summary: When `npm install` fails with ERESOLVE, identify the peer dependency conflict, then upgrade or replace the package or pin a nested version with `overrides`. `--legacy-peer-deps` skips peer checks and can hide the risk; npm 7+ installs peers by default.
Copy for agent
get the whatworks thread npm-install-eresolve-peer-dependency-conflict-before-force and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread npm-install-eresolve-peer-dependency-conflict-before-force
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks