Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
pnpm 10.x reference skill covering workspaces, catalogs, patches, peer deps, overrides, and CI/CD caching strategies.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/features-patches.md
1---2name: pnpm-patches3description: Patch third-party packages directly with customized fixes4---56# pnpm Patches78pnpm's patching feature lets you modify third-party packages directly. Useful for applying fixes before upstream releases or customizing package behavior.910## Creating a Patch1112### Step 1: Initialize Patch1314```bash15pnpm patch <pkg>@<version>1617# Example18pnpm patch [email protected]19```2021This creates a temporary directory with the package source and outputs the path:2223```24You can now edit the following folder: /tmp/abc123...25```2627### Step 2: Edit Files2829Navigate to the temporary directory and make your changes:3031```bash32cd /tmp/abc123...33# Edit files as needed34```3536### Step 3: Commit Patch3738```bash39pnpm patch-commit <path-from-step-1>4041# Example42pnpm patch-commit /tmp/abc123...43```4445This creates a `.patch` file in `patches/` and updates `package.json`:4647```48patches/49└── [email protected]50```5152```json53{54"pnpm": {55"patchedDependencies": {56"[email protected]": "patches/[email protected]"57}58}59}60```6162## Patch File Format6364Patches use standard unified diff format:6566```diff67diff --git a/lib/router/index.js b/lib/router/index.js68index abc123..def456 10064469--- a/lib/router/index.js70+++ b/lib/router/index.js71@@ -100,6 +100,7 @@ function createRouter() {72// Original code73- const timeout = 30000;74+ const timeout = 60000; // Extended timeout75return router;76}77```7879## Managing Patches8081### List Patched Packages8283```bash84pnpm list --depth=085# Shows (patched) marker for patched packages86```8788### Update a Patch8990```bash91# Edit existing patch92pnpm patch [email protected]9394# After editing95pnpm patch-commit <path>96```9798### Remove a Patch99100```bash101pnpm patch-remove <pkg>@<version>102103# Example104pnpm patch-remove [email protected]105```106107Or manually:1081. Delete the patch file from `patches/`1092. Remove entry from `patchedDependencies` in `package.json`1103. Run `pnpm install`111112## Patch Configuration113114### Custom Patches Directory115116```json117{118"pnpm": {119"patchedDependencies": {120"[email protected]": "custom-patches/my-express-fix.patch"121}122}123}124```125126### Multiple Packages127128```json129{130"pnpm": {131"patchedDependencies": {132"[email protected]": "patches/[email protected]",133"[email protected]": "patches/[email protected]",134"@types/[email protected]": "patches/@[email protected]"135}136}137}138```139140## Workspaces141142Patches are shared across the workspace. Define in the root `package.json`:143144```json145// Root package.json146{147"pnpm": {148"patchedDependencies": {149"[email protected]": "patches/[email protected]"150}151}152}153```154155All workspace packages using `[email protected]` will have the patch applied.156157## Best Practices1581591. **Version specificity**: Patches are tied to exact versions. Update patches when upgrading dependencies.1601612. **Document patches**: Add comments explaining why the patch exists:162```bash163# In patches/README.md164## [email protected]165Fixes timeout issue. PR pending: https://github.com/expressjs/express/pull/1234166```1671683. **Minimize patches**: Keep patches small and focused. Large patches are hard to maintain.1691704. **Track upstream**: Note upstream issues/PRs so you can remove patches when fixed.1711725. **Test patches**: Ensure patched code works correctly in your use case.173174## Troubleshooting175176### Patch fails to apply177178```179ERR_PNPM_PATCH_FAILED Cannot apply patch180```181182The package version changed. Recreate the patch:183```bash184pnpm patch-remove [email protected]185pnpm patch [email protected]186# Reapply changes187pnpm patch-commit <path>188```189190### Patch not applied191192Ensure:1931. Version in `patchedDependencies` matches installed version exactly1942. Run `pnpm install` after adding patch configuration195196<!--197Source references:198- https://pnpm.io/cli/patch199- https://pnpm.io/cli/patch-commit200- https://pnpm.io/package_json#pnpmpatcheddependencies201-->202