Skip to content
>_VibeUnstuck

npm error ERESOLVE unable to resolve dependency tree

Last verified:

The fix

npm error ERESOLVE unable to resolve dependency tree. Install a version whose peer matches this app. Do not start with --legacy-peer-deps.

  1. 1

    Read the Could not resolve dependency lines

    Copy the package name, the version npm tried, and the peer range under Could not resolve dependency. That pair is the conflict. Found is what you already have. Do not scroll past it to a generic prompt that says to fix dependencies.

  2. 2

    Install a version whose peers match the app

    Ask npm for the peers of a version you are willing to install. Pick a release that accepts the React, Next, or Vite version already in package.json. Downgrade the new package before you upgrade the whole framework. Replace the name and version in the command with the ones from the log.

    npm view some-package@1.2.3 peerDependencies
  3. 3

    Update the lockfile with a normal install

    After the range in package.json matches, run npm install with no legacy flag and commit package.json and package-lock.json together. Vercel and npm ci install that lockfile. If the lockfile was written with --legacy-peer-deps, npm ci needs the same flag or the trees will not match. That is why the flag is a poor default.

  4. 4

    Use a legacy flag only when you can name the risk

    If two direct dependencies truly cannot agree, --legacy-peer-deps is the escape hatch the error names, and npm says not to prefer it. A one-off command is easy to forget on the next machine. Do not put legacy-peer-deps=true in .npmrc, and do not run npm config set legacy-peer-deps true, on the first conflict. Write down which peer you ignored. --force is the other retry the log offers. It is not a matching version.

Why it happens

Current npm prints npm error code ERESOLVE and then npm error ERESOLVE unable to resolve dependency tree. Older npm prints the same sentence as npm ERR! ERESOLVE unable to resolve dependency tree. Under that, While resolving names your app, Found names the version already in the tree, and Could not resolve dependency names the package and the peer it wanted, such as peer react@"^18" from some-package@1.2.3. The log then says to fix the upstream conflict, or to retry with --force or --legacy-peer-deps to accept an incorrect and potentially broken resolution.

Since npm 7, peers are part of the tree. A direct dependency whose peer does not match what the app already has stops the install. npm's config docs say legacy-peer-deps ignores peerDependencies the way npm 3 through 6 did, and that using it is not recommended because it does not enforce the peer contract. Deleting package-lock.json and node_modules reruns the same solve. An AI adding the newest release of a library is the usual way a Lovable or Cursor app gets this on the next install.

The next error you'll probably hit

Once this is fixed, the usual follow-up is npm ci can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. npm ci refused to install because package.json and the lockfile describe different dependencies. Update the lockfile on purpose and commit it. That pin is the safer install.

Prompt to paste back into your AI tool

Paste this above the error.

npm install failed with: npm error ERESOLVE unable to resolve dependency tree.

The Could not resolve dependency block is:
<paste that block, including Found and the peer line>

npm --version is <version>.

Do not add --legacy-peer-deps or --force. Do not delete package-lock.json. Do not run npm config set legacy-peer-deps true. Do not upgrade React or Next unless I ask.

1. Name the package version that conflicts and the peer it requires.
2. Choose a version of that package whose peers match the version already in package.json. Show the npm view command you used.
3. Change only that dependency, then tell me to run npm install and commit the lockfile.
4. If no such version exists, say so and stop.

Common questions

+npm install --legacy-peer-deps worked. Is that the fix?

It skips the peer check. npm's config docs say that is not recommended, because other packages may rely on the peer contract. You can still get two Reacts or a missing API at runtime. Match the versions in the Could not resolve dependency lines first.

+Why did Vercel fail when the laptop installed fine?

The laptop has an older node_modules, a user-level legacy-peer-deps setting, or a lockfile the repo does not have. Commit package-lock.json after a clean npm install that does not need the flag. npm ci on the host will not rewrite the lock to make the conflict disappear.

+The log says npm ERR! ERESOLVE, not npm error ERESOLVE. Same bug?

Yes. npm ERR! ERESOLVE unable to resolve dependency tree is the older prefix for the same line. Current npm prints npm error ERESOLVE unable to resolve dependency tree. Read the peer block either way.

+An AI added a package and the install stopped. What do I change?

Only the package named under Could not resolve dependency. Pick a release whose peers accept the React or Next version already in package.json. Do not delete the lockfile to make the solver try again.

Related errors