npm ERESOLVE Unable to Resolve Dependency Tree
npm cannot install a package due to conflicting dependency requirements.
Explanation
npm ERESOLVE occurs when npm 7+ cannot resolve the dependency tree because two or more packages require incompatible versions of the same dependency. For example, Package A requires lodash@^3.0.0 while Package B requires lodash@^4.0.0. npm 7+ strictly checks peer dependencies by default (unlike npm 6 which used --legacy-peer-deps behavior). This error provides detailed information about the conflict. Common causes include outdated project dependencies, packages with strict peer dependency requirements, and monorepo version conflicts.
Common Causes
- Incompatible peer dependency versions
- Outdated project dependencies
- Packages with strict version requirements
- Monorepo version conflicts
- npm 7+ strict dependency resolution
Solution
Review the conflict details in the error message to understand which versions are incompatible. Try npm install --legacy-peer-deps to use npm 6-style behavior. Update the conflicting packages to versions with compatible peer dependencies. Use npm ls to inspect the current dependency tree. Check for outdated packages with npm outdated. Consider using resolutions in package.json to force a specific version. For monorepos, use workspace features to manage shared dependencies. Use npm-check-updates to update all packages at once.
Code Example
# ERESOLVE error when installing
npm install new-package
# ERESOLVE unable to resolve dependency tree
# Found: react@17.0.2
# peer react@"^16.8.0" from some-package@1.0.0
# Fix 1: use legacy peer deps
npm install new-package --legacy-peer-deps
# Fix 2: update conflicting packages
npm outdated
npm update
# Fix 3: force resolution in package.json
{
"resolutions": {
"react": "^18.0.0"
}
}
# Fix 4: check dependency tree
npm ls react
npm ls lodash
# Fix 5: use npm-check-updates
npx npm-check-updates -u
npm install
# For yarn users
yarn add new-package --legacy-peer-deps
# Check peer dependencies
npm info package-name peerDependencies
Error Information
Language
javascript
Framework
nodejs
Difficulty
Intermediate
Views
11
Related Errors
Frontend
WebSocket Connection Failed
The WebSocket connection could not be established or was closed unexpectedly.
JavaScript
TypeError: Cannot Read Property of Undefined
The code tries to access a property or method on an undefined or null value.
ECONNREFUSED
Database
ECONNREFUSED
The network connection was refused by the target server.
ERR_MODULE_NOT_FOUND
Node.js
ERR_MODULE_NOT_FOUND
Node.js cannot find the specified ES module file.