How do you write an npm override?
As a key under overrides in your root package.json, naming the package and the version to use. The value can be an exact version, a range, a dist-tag, or a replacement such as npm:, file: or a Git URL.
{
"overrides": {
"foo": "1.0.2",
"bar": "^2.3.1",
"baz": {
".": "4.0.0",
"qux": "1.1.0"
},
"parent@2.0.0": {
"foo": "1.0.2"
}
}
}
Line by line: foo becomes 1.0.2 everywhere; bar gets at least the patched 2.3.1; baz is pinned with "." and its child qux is pinned too; and foo changes only under version 2.0.0 of parent. Keys nest to any depth.
Can you override a direct dependency?
Only if the override and your dependency use the exact same spec; otherwise npm throws EOVERRIDE. To keep them in step, point the override at your dependency with $:
{
"dependencies": { "foo": "^1.2.0" },
"overrides": { "foo": "$foo" }
}
Can an override point at a fork?
Yes. Three forms work, nested too:
"package-name": "npm:@scope/forked-package@1.0.0"
"package-name": "github:username/repo#branch-name"
"package-name": "file:../local-fork"
The npm: form swaps in another package, github: takes a branch, tag or commit, and file: takes a local copy.
Why does my override do nothing?
Most often because it isn't in the root package.json. npm considers overrides only there: overrides inside installed dependencies, workspaces included, are ignored. The same rule means a library's overrides never reach the people who install it; a published package can only pin its dependencies or bundle them. If you have not tried it yet, npm audit fix may say why it stopped.
Where do pnpm overrides go?
In pnpm-workspace.yaml, at the root of the project. pnpm doesn't read settings from the pnpm field of package.json, and the overrides field works only at the root.
overrides:
"foo": "^1.0.0"
"bar@^2.1.0": "3.0.0"
"qar@1>zoo": "2"
The > selector limits a change to one parent: qar@1>zoo changes zoo only where qar@1 depends on it. A selector can name only one parent, and both sides take * wildcards on package names.
What about Yarn resolutions and Bun?
Yarn's field is resolutions, also root only; elsewhere it gives a warning. A key has one level of specificity: "relay-compiler": "3.0.0", or "webpack/memory-fs": "0.4.1" for a child. Bun reads npm's overrides or Yarn's resolutions from the root package.json (only overrides when both are there), also accepts pnpm's > form, and applies them to peer dependencies too.
| Tool | Change foo only under one parent |
|---|---|
| npm | Nested object: "parent": { "foo": "1.0.2" } |
| pnpm | "parent>foo": "1.0.2" |
| Yarn | "parent/foo": "1.0.2" |
| Bun | npm's object or pnpm's > |
From the npm v12, pnpm, Yarn and Bun documentation, read December 1, 2026.
How do you check an override worked?
Reinstall, then run npm audit, as in proving an npm audit fix: the advisory should be gone, and package-lock.json should show the version you chose under each parent. If the finding stays, the override's key probably doesn't match the path the vulnerable copy comes through.
Remove the override once the parent's own range includes a fixed version, so the tree goes back to versions its maintainers test together. Socket's socket fix can write npm overrides for you (OSV-Scanner's override strategy is Maven-only): see the remediation tools compared, and the five steps for where this fits.
How was this page checked?
Every rule and example was read from each package manager's own documentation on December 1, 2026; the npm example combines forms npm documents. Errors: support@winding.ai.