bun patch: Patch a Dependency In Place
bun patch makes a dependency editable, then bun patch --commit saves your edits as a patch that reapplies on every install.
bun patch is Bun's built-in equivalent of patch-package: fix a bug in a dependency without forking it, and have the fix reapplied deterministically in CI.
What it does
bun patch <pkg> copies the package into an editable location and points node_modules at it so you can change the files. bun patch --commit <path> then diffs your edits, writes a .patch file into patches/, and records it in package.json so bun install reapplies it everywhere.
Common usage
# 1. make the package editable
bun patch react
# 2. edit files under node_modules/react ...
# 3. persist the diff as a committed patch
bun patch --commit node_modules/reactOptions
| Form | What it does |
|---|---|
| bun patch <pkg> | Make the dependency editable in node_modules |
| bun patch --commit <path> | Save the edits as a patch and register it |
| (patches/ dir) | Where the generated .patch files are stored |
In CI
Commit the patches/ directory and the package.json patchedDependencies entry. On CI, bun install --frozen-lockfile reapplies the patch automatically, so the fix is part of the reproducible install. There is nothing extra to run in the pipeline once the patch is committed.
Common errors in CI
"error: patch failed to apply" after a dependency bump means the upstream code changed and the patch no longer matches; regenerate the patch against the new version with bun patch again. A patch that is not reflected in CI means patches/ or the package.json entry was not committed.