"overrides" and Yarn’s "resolutions" in package.json. These let you pin the version of a metadependency — a dependency of one of your dependencies — regardless of what version is requested by the package that depends on it.
When to use overrides
Consider a project with one dependency,foo, which depends on bar:
bun install, the resolved tree might be:
bar@4.5.6 has a security vulnerability and the fix is in bar@4.4.2, you can force a specific version of bar across the entire dependency tree using overrides.
npm overrides
Add an"overrides" field to package.json:
bar, whether it appears as a direct dependency or as a transitive dependency anywhere in the tree.
Bun currently supports only top-level
"overrides". Nested overrides (scoping an override to a specific dependency path) are not supported.Yarn resolutions
Yarn uses"resolutions" instead of "overrides". Bun supports this field to ease migration from Yarn.
"overrides", nested resolutions are not currently supported.
Forcing a direct dependency version
Overrides also work on your direct dependencies. This is useful when you want to lock a dependency to a specific patch version:Patching packages
To apply local code modifications to an installed package, usebun patch:
patches/ directory and recorded in package.json under patchedDependencies. Bun automatically applies the patch on every install.