npm ERR! ERESOLVE unable to resolve dependency tree
npm error ERESOLVE unable to resolve dependency tree ... Could not resolve dependency: peer react@"^18"
In short: Two packages want incompatible versions of a shared dependency (often React or Next.js), and npm refuses to guess.
Why it happens
Since npm 7, peer dependencies are enforced. AI tools often add a library whose latest version expects a different React/Next/ESLint major than the one in your project, or upgrade one package without its companions.
How to fix it
- Read the error: it names the package you're installing and the peer version it wants vs. what you have.
- Check if a newer version of that package supports your React/Next version (
npm view <pkg> peerDependencies). - Install a compatible version explicitly:
npm install <pkg>@<version>. - If you just upgraded React/Next, upgrade related packages together (e.g.
react+react-dom+@types/react). --legacy-peer-depsis a last resort for a package that works but hasn't updated its peer range. Note it in your README, because your host's build needs the same flag (or an.npmrcwithlegacy-peer-deps=true).
Don't: Don't delete package-lock.json and reinstall everything with --force as a first move. It can silently upgrade dozens of packages.
Copy-paste fix prompt
I'm getting this error in my app: npm error ERESOLVE unable to resolve dependency tree ... Could not resolve dependency: peer react@"^18" [Paste the full error, stack trace, and the file it points to here] Likely cause: Two packages want incompatible versions of a shared dependency (often React or Next.js), and npm refuses to guess. Task: Read the ERESOLVE output and package.json, identify the exact conflicting peer requirement, and propose the smallest version change that satisfies it. Explain if --legacy-peer-deps is genuinely needed. Rules: - First explain the root cause in 2 sentences and list the files you'll change. - Make the smallest change that fixes it. Don't refactor unrelated code. - Don't disable security or checks (RLS, auth, signature verification, type checking, CORS allow-all) to make the error disappear. - Never print or hard-code secret keys. - Finish by telling me exactly how to verify the fix.
Common with: Cursor, Bolt, Lovable, Claude Code. Last reviewed 2026-11-13.
Did this fix it?
(Placeholder: feedback isn't recorded yet.)