versioned_docs/version-10.x/cli/patch.md
Prepare a package for patching (inspired by a similar command in Yarn).
This command will cause a package to be extracted in a temporary directory intended to be editable at will.
Once you're done with your changes, run pnpm patch-commit <path> (with <path> being the temporary directory you received) to generate a patchfile and register it into your top-level manifest via the patchedDependencies field.
Usage:
pnpm patch <pkg name>@<version>
:::note
If you want to change the dependencies of a package, don't use patching to modify the package.json file of the package. For overriding dependencies, use overrides or a package hook.
:::
<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/0GjLqRGRbcY" title="The pnpm patch command demo" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; fullscreen"></iframe>The package that needs to be patched will be extracted to this directory.
Ignore existing patch files when patching.
This field is added/updated automatically when you run pnpm patch-commit. It defines patches for dependencies using a dictionary where:
Example:
patchedDependencies:
[email protected]: patches/[email protected]
Dependencies can be patched by version range. The priority order is:
A special case: the version range * behaves like a name-only patch but does not ignore patch failures.
Example:
patchedDependencies:
foo: patches/foo-1.patch
foo@^2.0.0: patches/foo-2.patch
[email protected]: patches/foo-3.patch
patches/foo-3.patch is applied to [email protected].patches/foo-2.patch applies to all foo versions matching ^2.0.0, except 2.1.0.patches/foo-1.patch applies to all other foo versions.Avoid overlapping version ranges. If you need to specialize a sub-range, explicitly exclude it from the broader range.
Example:
patchedDependencies:
# Specialized sub-range
"[email protected]": patches/foo.2.2.0-2.8.0.patch
# General patch, excluding the sub-range above
"foo@>=2.0.0 <2.2.0 || >2.8.0": patches/foo.gte2.patch
In most cases, defining an exact version is enough to override a broader range.
Added in: v10.7.0 (Previously named allowNonAppliedPatches)
When true, installation won't fail if some of the patches from the patchedDependencies field were not applied.
patchedDependencies:
express@4.18.1: patches/express@4.18.1.patch
allowUnusedPatches: true
Added in: v10.7.0
Controls how patch failures are handled.
Behaviour: