Fix a bug in a third-party npm package today without waiting for the maintainer to release an official update.
Commit a .patch file so every teammate and CI machine automatically gets your dependency fix on the next install.
Apply temporary workarounds to node_modules packages in a Docker-deployed app without breaking the build cache.
Works with npm and yarn v1 only, yarn v2+, pnpm, and Bun have built-in patch commands and do not require this tool.
patch-package is a tool for JavaScript and TypeScript projects that lets you make fixes to third-party packages in your node_modules folder and keep those fixes across installs. When a dependency has a bug, you normally have to wait for the maintainer to release a fix and then update your version. With patch-package, you edit the broken file directly inside node_modules, run a single command, and it creates a .patch file that records your changes. That patch file gets committed to your repository and is automatically reapplied whenever anyone runs npm install or yarn install. The workflow is simple: find the broken file inside node_modules, edit it, run npx patch-package package-name, then commit the resulting .patch file. Anyone who clones your project and installs dependencies will get your fix applied automatically. The setup is a one-time addition to your package.json scripts, adding a postinstall step that runs patch-package after every install. It works with npm and yarn v1. Yarn v2 and newer, as well as pnpm, have built-in patching features and do not require this tool. For projects deployed to servers or run inside containers, the README covers extra steps to make sure patches apply correctly, including how to handle caching in CI systems like CircleCI without accidentally skipping a patch update. The tool also handles less common scenarios: patching packages nested inside other packages, marking patches as dev-only so they are safely skipped in production environments, and creating multiple patch files for the same package. You can also apply or reverse patches manually using the patch-dir option or standard Unix tools. The project has over 11,000 stars and addresses a very common frustration in JavaScript development. It does not replace contributing fixes upstream or keeping your dependencies maintained, but it gives you a practical way to keep your project working while you wait for an official resolution.
← ds300 on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.