npm overrides in package.json do not change a dependency of a dependency
npm ls still shows the old version of the nested packageShort answer
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. A key that names the wrong parent also matches nothing. Fix the location, the spec or the scope, then check with npm ls.
Fix it fast
1Find out which cause you have
Ask npm which versions of the package are in the tree and who requires each one.
npm ls some-package2Match what you see, then jump to its fix
- 1
The block is in a workspace package or in a library under node_modulesThe overrides block sits in the wrong package.jsonFix - 2
npm install stops with EOVERRIDEThe package is also a direct dependency with a different specFix - 3
Only one branch of the tree is wrong, and the override covers a different branchThe key names the wrong parent, or the wrong version of itFix
- 1
What does the error look like?
npm ls still shows the old version of the nested packagenpm error code EOVERRIDE
Cause 1 of 3
The overrides block sits in the wrong package.json
1Check
Overrides in installed dependencies, workspaces included, are not considered. Only the root file counts.
grep -rn "overrides" package.json packages/*/package.json2Fix
Move the block to the package.json at the root of the project.
{
"overrides": {
"some-package": "2.1.0"
}
}3Verify
Install and list the package again.
npm install
npm ls some-packageConfirmed by docs.npmjs.com
Cause 2 of 3
The package is also a direct dependency with a different spec
1Check
When you depend on the package yourself, the override has to match your own spec or point to it with a $ reference.
grep -n "some-package" package.json2Fix
Reference the direct dependency instead of repeating a version.
{
"dependencies": { "some-package": "^2.1.0" },
"overrides": { "some-package": "$some-package" }
}3Verify
Install without the error.
npm install && npm ls some-packageConfirmed by docs.npmjs.com
Cause 3 of 3
The key names the wrong parent, or the wrong version of it
1Check
An override can be scoped to a parent, nested to any depth, and limited to one version of the parent with name@version.
npm ls some-package2Fix
Write the override under the parent that really requires it, as shown by npm ls.
{
"overrides": {
"parent-package": {
"some-package": "2.1.0"
}
}
}3Verify
The listing should show the version you set under that parent.
npm install && npm ls some-packageConfirmed by docs.npmjs.com
How do I stop it coming back?
- Keep every override in the root package.json, with a comment in your changelog saying why.
- Run npm ls for the overridden package in CI so a silent miss shows up.
- Remove an override when the parent package releases a fix.
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:
Related fixes
Back end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix