npm says an override conflicts with a direct dependency
npm error code EOVERRIDEShort answer
npm refuses an override for a package you also depend on directly, unless both specs are exactly the same. Fix it by writing the override as a $ reference to your own dependency, or by scoping the override under the parent package that pulls the nested copy, so the root dependency stays untouched.
Fix it fast
1Find out which cause you have
Compare the two places the package is named: dependencies and overrides in package.json. The specs must be identical, or the override must be scoped.
grep -n -B2 -A6 'react-error-overlay\|"overrides"' package.json2Match what you see, then jump to its fix
- 1
EOVERRIDE, and the package is in both dependencies and overrides with different version stringsThe override spec differs from the direct dependency specFix - 2
The version you want to pin belongs to a nested dependency of a tool such as react-scripts, while your own package.json lists anotherYou only want to change the copy that one tool installsFix
- 1
What does the error look like?
npm error code EOVERRIDEOverride for react-error-overlay@^6.0.9 conflicts with direct dependency
Cause 1 of 2
The override spec differs from the direct dependency spec
1Check
npm accepts an override for a direct dependency only when the override spec exactly matches the dependency spec. A caret in one place and a bare version in the other is a mismatch.
npm pkg get dependencies.react-error-overlay overrides.react-error-overlay2Fix
Use a $ reference. It takes the spec from your direct dependency, so the two can never drift apart.
{
"dependencies": {
"react-error-overlay": "^6.0.9"
},
"overrides": {
"react-error-overlay": "$react-error-overlay"
}
}3Verify
The install finishes without EOVERRIDE.
npm installConfirmed by docs.npmjs.com
Cause 2 of 2
You only want to change the copy that one tool installs
1Check
A global override applies to every copy of the package, including your direct one, which is what causes the conflict. Find who needs the nested copy.
npm ls react-error-overlay2Fix
Nest the override under the parent package, so it applies only when the package appears below that parent. The root dependency is then not overridden.
{
"overrides": {
"react-scripts": {
"react-error-overlay": "6.0.9"
}
}
}3Verify
npm ls lists the installed versions of the package, with the pinned one below the parent.
npm install
npm ls react-error-overlayConfirmed by docs.npmjs.com
How do I stop it coming back?
- Prefer $ references whenever the overridden package is also a direct dependency.
- Edit overrides only in the root package.json: npm reads no overrides from installed packages.
- Run npm ls on the package after every override change.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Back end
npm overrides in package.json do not change a dependency of a dependency
npm error code EOVERRIDE
npm reads overrides only from the root package.json, and an override for a package you also depend on directly must match your own spec or use a $ reference.
3 causes, each with a fixBack end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
npm start stops with Could not find a required file in a React app
Name: index.html
react-scripts checks for two files before the dev server starts: public/index.html and a src/index file.
3 causes, each with a fixBack end
Create React App says Node is too old, and npm will not run on the new one
npm does not support Node.js v10.19.0
The shell is running an old Node.js that is below the version Create React App needs.
3 causes, each with a fixBack end
npm audit stops with ENOLOCK because there is no lockfile
npm ERR! audit
npm audit sends the dependency tree from your lockfile to the registry.
2 causes, each with a fixBack end
npm run build says react-scripts: Permission denied in CI
sh: react-scripts: Permission denied
The shell found node_modules/.bin/react-scripts but may not run it.
3 causes, each with a fix