Fix "npm ERR! ERESOLVE unable to resolve dependency tree"
npm ERR! ERESOLVE unable to resolve dependency tree
- npm error code ERESOLVE
- npm error ERESOLVE unable to resolve dependency tree
- npm ERR! ERESOLVE could not resolve
- npm ERR! Could not resolve dependency: npm ERR! peer react@"^18.0.0" from [email protected]
- npm ERR! Conflicting peer dependency: [email protected]
npm refuses to install because two packages require incompatible versions of the same dependency, most often a peer dependency (React, ESLint, Angular). The real fix is to update the blocking package or align versions; --legacy-peer-deps is only a workaround.
What this error means
A peer dependency is a library a package uses without bundling it: a React plugin declares for example "peerDependencies": { "react": "^18.0.0" } and relies on your project’s React version. Since npm 7, peer dependencies are installed and checked automatically. If your project uses react@19 and a package only accepts ^18, npm cannot build a tree that satisfies everyone and stops with ERESOLVE. The message shows the version found ("Found:") and the requirement that fails ("Could not resolve dependency:"). Since npm 10, the npm ERR! prefix has become npm error.
Common causes
- Major version upgrade: you move to React 19, ESLint 9 or Angular N+1 before a library has widened its peer dependency.
- Old or abandoned package: a dependency is no longer maintained and only accepts old versions.
- Mixed versions of one family:
@angular/coreand@angular/router, or ESLint plugins from different major versions. - Project created with npm 6 or
--legacy-peer-deps: the conflict already existed but was ignored, and comes back on a fresh install.
Step-by-step fix
-
Read the conflict
Scroll up in the output: the "Found:" line gives the installed version (for example
[email protected]) and "Could not resolve dependency: peer react@"^18.0.0" from [email protected]" gives the blocking package. The full report is also saved in theeresolve-report.txtfile named at the end. -
Look for a compatible version of the blocking package
Check the peer dependencies of the latest version: an update is often enough.
npm view some-lib peerDependencies npm view some-lib@latest version npm install some-lib@latest -
Align versions
If no compatible version exists, pick the main dependency version accepted by everyone (for example stay on React 18 until the library catches up), or replace the abandoned library.
npm install react@18 react-dom@18 -
Force a targeted version with
overridesIf you have checked that the library works with your version, declare it in
package.json.$reactreuses the React version declared in your dependencies. The workaround only affects that package; then runnpm installagain.{ "dependencies": { "react": "^19.0.0", "some-lib": "^2.3.0" }, "overrides": { "some-lib": { "react": "$react" } } } -
Last resort:
--legacy-peer-depsThis option restores npm 6 behavior: peer dependencies are ignored for the whole tree. The install succeeds, but nothing guarantees the packages work together.
--forceis even more permissive. If you use it, document it and remove it as soon as the library is updated.npm install --legacy-peer-deps -
Check the final tree
After the fix, check that only one version of the shared dependency remains and that no error is reported, then commit
package.jsonandpackage-lock.jsontogether.npm ls react
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Before a major upgrade, check your libraries’ peer dependencies with
npm view <package> peerDependencies. - Avoid
legacy-peer-deps=truein.npmrc: it applies to the whole team and CI and hides future conflicts. - Update packages from the same family together (all
@angular/*, all ESLint plugins) rather than one by one.
Frequently asked questions
What is the difference between --legacy-peer-deps and --force?
--legacy-peer-deps ignores peer dependencies. --force overrides every conflict and can install several incompatible versions. Both are workarounds to avoid when an update is possible.
Why does the error appear with npm but not with Yarn or pnpm?
Yarn and pnpm report unmet peer dependencies as a warning without blocking the install. The conflict is still there.
Does deleting node_modules and package-lock.json fix ERESOLVE?
Not if the conflict comes from the versions declared in package.json: npm will compute the same tree and fail again. You need to change versions or add an overrides entry.
Useful tools for this error
More JavaScript & Node.js errors
- Fix "Cannot read properties of undefined" in JavaScript
- Fix "blocked by CORS policy: No 'Access-Control-Allow-Origin' header"
- Fix "Unexpected token '<', "<!DOCTYPE "... is not valid JSON"
- Fix "Error: Cannot find module" in Node.js
- Fix "Hydration failed because the server rendered HTML didn’t match the client" (React, Next.js)
- Fix "Too many re-renders. React limits the number of renders" in React
- Fix "Error: listen EADDRINUSE: address already in use" in Node.js
- Fix "SyntaxError: Cannot use import statement outside a module"