The ERESOLVE error occurs when npm 7+ encounters conflicting peer dependency requirements. Use --legacy-peer-deps for a quick fix, or resolve the underlying version conflicts for a permanent solution.
npm 7 introduced strict peer dependency resolution that fails when packages declare incompatible peer dependency requirements. This is a significant change from npm 6, which only warned about peer dependency conflicts. The error occurs when npm cannot find a version of a package that satisfies all peer dependency constraints in your dependency tree. For example, if package A requires React 17 and package B requires React 18, npm cannot satisfy both requirements simultaneously and throws ERESOLVE.
Revert to npm 6 peer dependency behavior:
# For single install
npm install --legacy-peer-deps
# For specific package
npm install package-name --legacy-peer-depsThis ignores peer dependency conflicts and proceeds with installation.
Add to .npmrc for project-wide setting:
# Create or edit .npmrc in project root
echo "legacy-peer-deps=true" >> .npmrcNow all npm install commands will use legacy resolution.
Bypass all safety checks (use with caution):
npm install --forceWarning: This may install incompatible versions that cause runtime errors.
Sometimes conflicts arise from corrupted lockfile state:
# Remove cached dependency state
rm -rf node_modules package-lock.json
# Reinstall fresh
npm install
# Or with legacy peer deps
npm install --legacy-peer-depsFor a proper fix, identify the conflicting packages:
# See outdated packages
npm outdated
# Check what versions are available
npm view package-name versions
# Update the conflicting package
npm install package-name@latestUpdate packages to versions compatible with your framework version.
Force specific versions using package.json overrides:
{
"overrides": {
"react": "^18.2.0"
}
}This tells npm to use React 18 everywhere, regardless of peer dependency declarations.
Yarn often handles peer dependencies more gracefully:
# Install Yarn
npm install -g yarn
# Remove npm artifacts
rm -rf node_modules package-lock.json
# Install with Yarn
yarn installYarn uses a different resolution algorithm that may avoid the conflict.
Using --legacy-peer-deps or --force masks underlying compatibility issues. Packages installed may conflict at runtime, causing duplicate package instances, incorrect behavior, or hard-to-debug errors. For production applications, investigate and resolve the root cause.
Common scenarios requiring this fix:
- Upgrading React 17 → 18 with packages not yet supporting React 18
- Angular major version upgrades
- Using beta/release candidate versions of frameworks
- Older packages no longer maintained
For CI/CD, add legacy-peer-deps=true to .npmrc in the repository, or modify install commands. GitHub Actions example:
- run: npm ci --legacy-peer-depsnpm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error