Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm overrides in package.json do not change a dependency of a dependency

Errornpm ls still shows the old version of the nested package

Short 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.

  • Applies to npm 10, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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-package
  2. 2Match what you see, then jump to its fix

    1. 1The block is in a workspace package or in a library under node_modulesThe overrides block sits in the wrong package.jsonFix
    2. 2npm install stops with EOVERRIDEThe package is also a direct dependency with a different specFix
    3. 3Only 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

What does the error look like?

  • npm ls still shows the old version of the nested package
  • npm 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.json

2Fix

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-package

Confirmed by docs.npmjs.com

Did this fix it?

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.json

2Fix

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-package

Confirmed by docs.npmjs.com

Did this fix it?

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-package

2Fix

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-package

Confirmed by docs.npmjs.com

Did this fix it?

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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.