npmDependencies

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

  1. Read the error: it names the package you're installing and the peer version it wants vs. what you have.
  2. Check if a newer version of that package supports your React/Next version (npm view <pkg> peerDependencies).
  3. Install a compatible version explicitly: npm install <pkg>@<version>.
  4. If you just upgraded React/Next, upgrade related packages together (e.g. react + react-dom + @types/react).
  5. --legacy-peer-deps is 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 .npmrc with legacy-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

3 · The fix promptPaste into Cursor, Claude Code, Codex, Lovable, Bolt, Replit or v0
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.

Related fixes

← All fixes · Still stuck? Use the diagnose-first prompt