CalcSnippets
DevOps 5 min read

Use pnpm `overrides` to Fix a Transitive Dependency Deliberately

pnpm overrides can pin a transitive package when a fix or compatibility constraint requires it. Scope and verify the override instead of hiding a broken dependency graph.

An override is a policy decision

When a nested dependency has a known defect or security fix, pnpm's overrides can force a version across the dependency graph. That is useful when the direct package has not released a compatible update yet. It can also make an incompatible graph appear installable, so the override needs an owner and a removal condition.

Declare the narrowest supported override in the root package.json, then regenerate the lockfile with the repository's pinned pnpm version. Inspect the diff to see which dependency paths changed. Do not add an override in an arbitrary workspace package if the repository's pnpm configuration only honors it at the root.

Test the actual consumer

Run the package's tests and the application path that exercises the transitive library. A successful install only proves the resolver accepted the graph. It does not prove the newer package preserves APIs expected by every parent dependency.

Use pnpm why package-name to understand why the package exists and which parents consume it. Prefer upgrading the direct dependency when that release includes the fix. If an override remains necessary, document the issue or advisory, the compatible range, and the condition for removing the override.

Review overrides during dependency updates. A forgotten pin can block security fixes or create duplicate assumptions after upstream packages catch up. Keep the override small and visible; do not turn the field into a general mechanism for forcing every dependency to the newest release.

Scope and explain the exception

Before changing the root override, capture the package name, affected version range, broken behavior, and the direct dependency path that brings it in. pnpm why helps show whether several top-level packages rely on the same transitive module. If the issue affects one branch of the graph, use the narrowest override form supported by the package manager version used by the repository. A repository-wide pin can otherwise change unrelated consumers that rely on a different compatible range.

Check whether the intended version is compatible with its parents. An override changes resolution; it does not negotiate an API contract with packages that declared a different range. Read the dependency's release notes and run tests that cross the package boundary. For a security fix, verify that the resolved version contains the fix and that the lockfile records it. For a compatibility workaround, test feature paths that exercise the overridden code and record the upstream issue or target upgrade.

Keep the lockfile and lifecycle aligned

Apply the override using the repository's pinned pnpm version and review the lockfile diff. Confirm that the changed package appears under the expected importers and unrelated dependencies did not move. Run a clean frozen install in CI so another pnpm version does not silently rewrite the graph. If the override changes a package with native code or install scripts, test the full build, not only JavaScript unit tests.

Every override should have an owner and a removal signal. That can be an upstream release, a minimum supported version in a direct dependency, or closure of a tracked defect. Revisit overrides during dependency reviews. When the parent package adopts a compatible version, remove the override and regenerate the lockfile deliberately. A temporary pin that survives for years becomes undocumented policy and can prevent security updates just as easily as it once delivered one.

When the dependency is security-sensitive, record the advisory identifier and how the patched version was verified. A forced version may fix one vulnerability while introducing an API incompatibility or another transitive exposure. Include the affected runtime path in the regression test and use the package's supported release channel where possible. This turns an override from an unexplained resolver trick into a small risk decision the next maintainer can revisit.

Scope and explain the exception

Before changing the root override, capture the package name, affected version range, broken behavior, and the direct dependency path that brings it in. pnpm why helps show whether several top-level packages rely on the same transitive module. If the issue affects one branch of the graph, use the narrowest override form supported by the package manager version used by the repository. A repository-wide pin can otherwise change unrelated consumers that rely on a different compatible range.

Check whether the intended version is compatible with its parents. An override changes resolution; it does not negotiate an API contract with packages that declared a different range. Read the dependency's release notes and run tests that cross the package boundary. For a security fix, verify that the resolved version contains the fix and that the lockfile records it. For a compatibility workaround, test feature paths that exercise the overridden code and record the upstream issue or target upgrade.

Keep the lockfile and lifecycle aligned

Apply the override using the repository's pinned pnpm version and review the lockfile diff. Confirm that the changed package appears under the expected importers and unrelated dependencies did not move. Run a clean frozen install in CI so another pnpm version does not silently rewrite the graph. If the override changes a package with native code or install scripts, test the full build, not only JavaScript unit tests.

Every override should have an owner and a removal signal. That can be an upstream release, a minimum supported version in a direct dependency, or closure of a tracked defect. Revisit overrides during dependency reviews. When the parent package adopts a compatible version, remove the override and regenerate the lockfile deliberately. A temporary pin that survives for years becomes undocumented policy and can prevent security updates just as easily as it once delivered one.

Keep reading

Related guides