ERESOLVE unable to resolve dependency tree

npm stopped installing because a package only supports a different version of something your project already uses, most often React.

Terminal and build log
npm error code ERESOLVE npm error ERESOLVE unable to resolve dependency tree npm error npm error While resolving: my-app@0.1.0 npm error Found: react@19.2.0 npm error node_modules/react npm error react@"^19.2.0" from the root project npm error npm error Could not resolve dependency: npm error peer react@"^16.8.5 || ^17.0.0 || ^18.0.0" from react-beautiful-dnd@13.1.1 npm error node_modules/react-beautiful-dnd npm error react-beautiful-dnd@"^13.1.1" from the root project npm error npm error Fix the upstream dependency conflict, or retry npm error this command with --force or --legacy-peer-deps npm error to accept an incorrect (and potentially broken) dependency resolution.

Also appears as

  • npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree
  • npm error code ERESOLVE npm error ERESOLVE could not resolve
  • npm warn ERESOLVE overriding peer dependency

Prompt to fix it

npm install fails with "ERESOLVE unable to resolve dependency tree". Read the Found and Could not resolve dependency lines and tell me which package conflicts with which version. Check whether a newer version of that package supports our versions, and upgrade it. If it’s unmaintained, suggest a maintained replacement and update the code that uses it. Don’t use --force, and only use --legacy-peer-deps if there’s no other option, after telling me the risk. Make sure a clean npm install works afterward.

Paste into Layerwise or any AI coding tool.

What it means

Some packages declare peer dependencies: other packages they expect you to install, in a version range they support. Since npm 7, npm install enforces those ranges, and this error means no single version satisfies everyone. Read it in two parts: Found is what your project uses, and Could not resolve dependency names the package whose range leaves it out.

Here, the app uses React 19, and react-beautiful-dnd only lists React 16 to 18. That happens a lot with AI-generated code: the tool picks a well-known package from its training data, and that package stopped getting updates before the current React or Next.js came out.

npm suggests --force or --legacy-peer-deps. Both finish the install by ignoring the conflict, and the package may then crash or misbehave at runtime. A legacy-peer-deps=true line in .npmrc does the same for every install, often without anyone noticing. Use them only as a last resort, after you’ve tested the package with your versions. A newer release or a maintained replacement fixes it properly.

Common causes

  • The code uses a package whose latest release doesn’t list your React or Next.js version as supported.
  • A core package was upgraded, such as React 18 to 19, while related packages like a UI kit or testing library stayed on old releases.
  • Two packages need different major versions of the same peer, such as plugins built for different ESLint versions.
  • The project was installed locally with --legacy-peer-deps, and the server’s clean npm install applies npm’s strict rules.

How to fix it

  1. Read the Could not resolve dependency block. It names the package and the version range it accepts.
  2. Check that package for a newer release that supports your versions, using npm view <name> peerDependencies, and install it with npm install <name>@latest.
  3. If the package is unmaintained, switch to a maintained replacement, such as @hello-pangea/dnd for react-beautiful-dnd, and update the code that uses it.
  4. If an upgrade caused it, upgrade the related packages at the same time, or pin the shared package to a version every package accepts.
  5. As a last resort, install with --legacy-peer-deps after testing that the package works with your versions. Put legacy-peer-deps=true in .npmrc so the server installs the same way, and remove it once the package catches up.

Example fix

# Which React versions does each package accept?
npm view react-beautiful-dnd peerDependencies
npm view @hello-pangea/dnd peerDependencies

# Swap in the maintained fork, then install normally.
npm uninstall react-beautiful-dnd
npm install @hello-pangea/dnd
All errors
Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.

Invalid hook call

A hook such as useState ran somewhere React can’t track it, or the app loaded two copies of React that don’t know about each other.

> my-app@0.0.0 dev > vite sh: vite: command not found

vite: command not found

The shell couldn’t find the vite program, almost always because the project’s packages aren’t installed or the command ran in the wrong folder.

Error: Command "npm run build" exited with 1

Command "npm run build" exited with 1

Your build script failed on the host. This line only reports the failure; the actual error is printed earlier in the build log.

Error: Cannot find module 'express' Require stack: - /Users/me/my-app/server.js

Cannot find module

Node tried to load a package or file that isn’t where the code says it is, usually because it was never installed or the path is wrong.

Build with an agent that checks its work

The Layerwise agent clicks through the live preview and reads the console, so it catches errors before you do.