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
peerDependenciesautomatically, 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-depsrestores 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 rootpackage.jsonkey 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 (otherwiseEOVERRIDE). - 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
--forceand committing a lockfile built from it, so teammates and CI hit the same wall or a different one. - Adding
legacy-peer-deps=trueto.npmrcfor the whole project to silence one package. - Writing an
overridesentry for a direct dependency with a different spec (fails withEOVERRIDE). - 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