Back

Fix 'npm ERR! ERESOLVE unable to resolve dependency tree'

Fix 'npm ERR! ERESOLVE unable to resolve dependency tree'

The dreaded npm ERR! ERESOLVE unable to resolve dependency tree error stops countless developers in their tracks every day. This npm install error appears when npm cannot find compatible versions of packages that work together, creating a dependency conflict that blocks installation. Here’s how to understand and fix it quickly.

Key Takeaways

  • ERESOLVE errors occur when npm cannot satisfy all package version requirements simultaneously
  • npm 7+ enforces stricter dependency checking compared to npm 6
  • Version alignment is the most reliable fix, while flags like —legacy-peer-deps offer quick workarounds
  • Regular dependency updates and compatibility checks prevent future conflicts

What Does the npm ERESOLVE Error Mean?

The ERESOLVE error occurs when npm’s dependency resolution algorithm cannot satisfy all version requirements simultaneously. Starting with npm 7, the package manager became stricter about peer dependencies and version conflicts—what used to be warnings in npm 6 now throw errors.

When you see this error, npm is essentially saying: “Package A needs version 1.0 of a dependency, but Package B needs version 2.0, and I can’t install both.”

Why npm Dependency Tree Conflicts Happen

Version Mismatches

The most common cause involves incompatible version requirements between packages. For example, in an Angular project:

npm ERR! Found: @angular/core@11.0.3
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^9.1.0 || ^10.0.0" from @agm/core@3.0.0

Here, your project has Angular 11, but the @agm/core package only supports Angular 9 or 10.

Peer Dependencies

Peer dependencies are packages that aren’t directly installed but are expected to exist in your project. When different packages require different versions of the same peer dependency, Node.js package conflicts arise. This is especially common with:

  • React and React Native libraries requiring specific React versions
  • Angular packages needing matching core versions
  • Next.js plugins expecting particular ESLint configurations

npm Version Changes

The shift from npm 6 to npm 7+ introduced stricter dependency checking. What previously installed with warnings now fails completely, forcing developers to address the underlying conflicts.

How to Fix the npm Dependency Tree Error

First, identify the conflicting packages:

npm ls

Then update the problematic packages to compatible versions:

npm update package-name
# or install a specific version
npm install package-name@version

For the Angular example above, you’d either:

  • Update @agm/core to a version supporting Angular 11
  • Downgrade Angular to version 10

Solution 2: Clean Install

Sometimes, clearing everything helps:

rm -rf node_modules package-lock.json
npm cache clean --force
npm install

This forces npm to recalculate the entire dependency tree from scratch.

Solution 3: Use —legacy-peer-deps Flag

When you need a quick workaround, the --legacy-peer-deps flag tells npm to use the old npm 6 resolution algorithm:

npm install --legacy-peer-deps

To make this permanent for your project:

npm config set legacy-peer-deps true

Important: While this solves the immediate problem, it bypasses npm’s safety checks. Your packages might not work correctly together.

Solution 4: Use —force Flag

The --force flag ignores all dependency conflicts:

npm install --force

Warning: This is the riskiest option. Use it only when you understand the consequences and have no other choice.

Real-World Examples

Next.js ESLint Conflict

npm ERR! peer eslint@"^7.23.0 || ^8.0.0" from eslint-config-next@14.0.4

Fix: Update to the latest eslint-config-next:

npm install eslint-config-next@latest --save-dev

React Native Version Mismatch

npm ERR! peer react@"18.0.0" from react-native@0.70.0

Fix: Ensure React and React Native versions are compatible by checking the React Native compatibility table.

Best Practices to Prevent npm Install Errors

  1. Keep dependencies updated regularly - Don’t let packages fall too far behind
  2. Check compatibility before upgrading - Use npm outdated to see available updates
  3. Use exact versions in production - Consider using exact versions (1.2.3 instead of ^1.2.3) for critical dependencies
  4. Document version requirements - Note any specific version combinations that work in your README

When to Use Each Solution

  • Version alignment: Always try this first—it’s the proper fix
  • Clean install: When package-lock.json might be corrupted
  • —legacy-peer-deps: For older projects or when you understand the risks
  • —force: Last resort for development environments only

Conclusion

The npm ERESOLVE error is frustrating but solvable. While flags like --legacy-peer-deps and --force offer quick fixes, the most stable solution remains updating packages to compatible versions. Understanding why these Node.js package conflicts occur helps you choose the right fix for your situation and prevent future npm dependency tree issues.

FAQs

The --force flag ignores all conflicts and warnings during installation, while --legacy-peer-deps specifically uses npm 6's less strict peer dependency resolution. Legacy peer deps is safer as it only affects peer dependency handling, whereas force bypasses all safety checks.

Yes, run npm config set legacy-peer-deps true globally. However, this isn't recommended as it applies to all projects on your machine. Instead, add a .npmrc file with legacy-peer-deps=true to specific projects that need it.

This typically happens when you upgrade npm from version 6 to 7 or higher, update a package that introduces new peer dependencies, or when a dependency updates its own requirements. Check your npm version with npm -v and recent package changes.

Understand every bug

Uncover frustrations, understand bugs and fix slowdowns like never before with OpenReplay — the open-source session replay tool for developers. Self-host it in minutes, and have complete control over your customer data. Check our GitHub repo and join the thousands of developers in our community.

OpenReplay