How to fix npm ERR! code EOVERRIDECONFLICT npm ERR! Override conflicts with existing dependency in npm
The EOVERRIDECONFLICT error occurs when your package.json overrides section specifies a version that conflicts with a direct dependency. Fix it by using the $ reference syntax or matching version specifications exactly.
Quick fix
Fixes EOVERRIDECONFLICT
"overrides": {
"react-error-overlay": "$react-error-overlay"
}- Use the $ reference syntax
- Match version specifications exactly
- Clear cache and reinstall
- Remove unnecessary overrides
"overrides": {"react-error-overlay": "$react-error-overlay"}npm ERR! code EOVERRIDECONFLICTnpm ERR! Override conflicts with existing dependency
What this error means
This error means npm detected a conflict between your overrides configuration and a direct dependency in your package.json. The overrides feature (introduced in npm 8.3.0) allows you to replace specific versions of packages in your dependency tree, but npm requires that overrides for direct dependencies must match exactly or use special reference syntax. When you specify an override like `"axios": "^1.2.0"` but your direct dependency says `"axios": "1.2.5"`, npm cannot determine which version specification should take precedence. This validation prevents accidental version mismatches that could lead to runtime errors or security vulnerabilities. The error is npm's way of enforcing intentional, deliberate overrides rather than accidental conflicts that might break your dependency tree.
Typical symptoms
- npm install fails immediately with EOVERRIDECONFLICT error
- Error message shows "Override for [package] conflicts with direct dependency"
- Build pipelines break in CI/CD after dependency updates
- Error appears after upgrading to npm 8.3.0 or later
- Occurs when tools like npm-check-updates modify dependencies without updating overrides
- npm ci fails while npm install with --force might work
Common causes
- Override specifies a different version range than the direct dependency (e.g., "^1.2.0" vs "1.2.5")
- Direct dependency was updated but the corresponding override was not
- Not using the $package-name reference syntax for overriding direct dependencies
- Stale package-lock.json containing old override resolutions
- Automated dependency update tools modifying dependencies without syncing overrides
- Copy-pasting override configurations from other projects without adjustment
How to fix "npm ERR! code EOVERRIDECONFLICT npm ERR! Override conflicts with existing dependency"
The recommended solution is to use npm's reference syntax, which automatically tracks the direct dependency version:
"overrides": {
"react-error-overlay": "$react-error-overlay"
}This tells npm to use whatever version is specified in your dependencies/devDependencies for this package. The override will automatically stay in sync if you update the dependency later.
If you need to specify an explicit version, ensure the override matches the direct dependency exactly:
"dependencies": {
"axios": "^1.2.0"
},
"overrides": {
"axios": "^1.2.0"
}Both specifications must be identical strings, not just semantically equivalent versions.
If the conflict persists after fixing package.json, clear your npm cache and reinstall:
rm -rf node_modules package-lock.json
npm cache clean --force
npm installStale lockfiles often contain old override resolutions that conflict with updated configurations.
Review your overrides section and remove any that are no longer needed. Fewer overrides means fewer potential conflict points. Only keep overrides that serve a specific purpose like security patches or compatibility fixes.
If other solutions fail and you need to proceed urgently:
npm install --legacy-peer-depsWarning: This disables override validation entirely and may result in an inconsistent dependency tree. Only use for temporary debugging, not production builds.
Advanced notes
The overrides feature was introduced in npm 8.3.0 (bundled with Node.js 16.13.0+) to allow developers to replace packages anywhere in the dependency tree. This is particularly useful for security patches in transitive dependencies.
In CI/CD pipelines, use npm ci instead of npm install to ensure reproducible builds from your lockfile. When using dependency update bots like Dependabot or Renovate, configure them to update both dependencies and corresponding overrides together.
For monorepo setups, consider using workspace-level overrides in the root package.json to maintain consistency across packages.
Frequently asked questions
- What does "EOVERRIDECONFLICT" mean?
- json. 0) allows you to replace specific versions of packages in your dependency tree, but npm requires that overrides for direct dependencies must match exactly or use special reference syntax. 5", npm cannot determine which version specification should take precedence.
- How do I fix "EOVERRIDECONFLICT"?
- The EOVERRIDECONFLICT error occurs when your package.json overrides section specifies a version that conflicts with a direct dependency. Fix it by using the $ reference syntax or matching version specifications exactly.
- What causes "EOVERRIDECONFLICT"?
- Override specifies a different version range than the direct dependency (e.g., "^1.2.0" vs "1.2.5") Direct dependency was updated but the corresponding override was not Not using the $package-name reference syntax for overriding direct dependencies
- Is the "EOVERRIDECONFLICT" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐ฌ
- ๐GitHub #4232: npm/cli(GitHub)
- ๐