To install patches with Composer, I install composer-patches with the command
composer require cweagans/composer-patches
Version 2.0.0 is installed, but it doesn't currently work with Drupal 11.

If I install it like this:
composer require cweagans/composer-patches:^1.7
everything works.

Am I right in thinking that cweagans/composer-patches version 2.0.0 is not yet compatible with Drupal? Is there any official information about this?

---
See #14 for a possible solution.

Comments

vasyok created an issue. See original summary.

vasyok’s picture

Issue summary: View changes
cilefen’s picture

What is the evidence that it is incompatible? That information is missing from the issue summary.

cilefen’s picture

vasyok’s picture

What is the evidence?
With composer-patches v 2 patches does not applied.

cilefen’s picture

Do you have some Composer debug logging? Did you configure the patch tool as documented?

May we see the composer.json file?

cilefen’s picture

Actually, the configuration should be the same between versions. Let’s please see the verbose Composer output

cilefen’s picture

Category: Task » Support request

I did some testing and everything is working on a site that I have with many patches. Follow the composer-patches troubleshooting guide as some things have changed.

Probably Drupal itself is not involved in your difficulties.

vasyok’s picture

With cweagans/composer-patches ~2.0, patches defined in extra.patches are silently not applied in a standard drupal/recommended-project setup.

Downgrading to ^1.7.x applies the same patches correctly.

Note: composer patches-doctor is only available in 2.x, so its absence in 1.7.x is expected and not an error.

start composer.json obtained from https://github.com/drupal/recommended-project/tree/11.3.x

not a working solution

with cweagans/composer-patches v 2.0 this file:

{
    "name": "drupal/recommended-project",
    "description": "Project template for Drupal projects with a relocated document root",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "homepage": "https://www.drupal.org/project/drupal",
    "support": {
        "docs": "https://www.drupal.org/docs/user_guide/en/index.html",
        "chat": "https://www.drupal.org/node/314178"
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ],
    "require": {
        "composer/installers": "^2.3",
        "cweagans/composer-patches": "~2.0",
        "drupal/core-composer-scaffold": "^11.3",
        "drupal/core-project-message": "^11.3",
        "drupal/core-recipe-unpack": "^11.3",
        "drupal/core-recommended": "^11.3"
    },
    "require-dev": {
        "drupal/core-dev": "^11.3"
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "allow-plugins": {
            "composer/installers": true,
            "cweagans/composer-patches": true,
            "dealerdirect/phpcodesniffer-composer-installer": true,
            "drupal/core-composer-scaffold": true,
            "drupal/core-project-message": true,
            "drupal/core-recipe-unpack": true,
            "php-http/discovery": true,
            "php-tuf/composer-integration": true,
            "phpstan/extension-installer": true,
            "tbachert/spi": true
        },
        "sort-packages": true
    },
    "extra": {
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
            }
        },
        "installer-paths": {
            "web/core": ["type:drupal-core"],
            "web/libraries/{$name}": ["type:drupal-library"],
            "web/modules/contrib/{$name}": ["type:drupal-module"],
            "web/profiles/contrib/{$name}": ["type:drupal-profile"],
            "web/themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/Commands/contrib/{$name}": ["type:drupal-drush"],
            "web/modules/custom/{$name}": ["type:drupal-custom-module"],
            "web/profiles/custom/{$name}": ["type:drupal-custom-profile"],
            "web/themes/custom/{$name}": ["type:drupal-custom-theme"],
            "recipes/{$name}": ["type:drupal-recipe"]
        },
        "drupal-core-project-message": {
            "include-keys": ["homepage", "support"],
            "post-create-project-cmd-message": [
                "<bg=blue;fg=white>                                                         </>",
                "<bg=blue;fg=white>  Congratulations, you’ve installed the Drupal codebase  </>",
                "<bg=blue;fg=white>  from the drupal/recommended-project template!          </>",
                "<bg=blue;fg=white>                                                         </>",
                "",
                "<bg=yellow;fg=black>Next steps</>:",

                "  * Install the site: https://www.drupal.org/docs/installing-drupal",
                "  * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
                "  * Get support: https://www.drupal.org/support",
                "  * Get involved with the Drupal community:",
                "      https://www.drupal.org/getting-involved",
                "  * Remove the plugin that prints this message:",
                "      composer remove drupal/core-project-message"
            ]
        },
        "composer-exit-on-patch-failure": true,
        "patchLevel": {
            "drupal/core": "-p2"          
        },
        "patches": {
            "drupal/core": {
                "Popular tags with brackets": "web/patches/2924783-18.patch"
            }                  
        }
    }
}

Command composer patches-doctor write:

System information
================================================================================
Composer version:                                                         2.8.12
PHP version:                                                              8.4.14

Available patchers
================================================================================
cweagans\Composer\Patcher\GitPatcher usable:                                 yes
cweagans\Composer\Patcher\GitInitPatcher usable:                             yes
cweagans\Composer\Patcher\FreeformPatcher usable:                            yes
Has usable patchers:                                                         yes

Common configuration issues
================================================================================
has plain http patch URLs:                                                    no

working solution

composer.json same as above but with

"require": {
...
        "cweagans/composer-patches": "^1.7",
...  
  },
cilefen’s picture

Let’s get all debug information for some support.

cilefen’s picture

We need the output of composer patches-repatch -vvv. It is very unlikely something to do with Drupal but the debug log will help you.

mortona2k’s picture

Status: Postponed (maintainer needs more info) » Active

I also can't apply a core patch.

Output of composer patches-repatch -vvv:

Reading ./composer.json (/var/www/html/composer.json)
Loading config file ./composer.json (/var/www/html/composer.json)
Checked CA file /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem does not exist or it is not a file.
Checked directory /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem does not exist or it is not a directory.
Checked CA file /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid
Executing command (/var/www/html): 'git' 'branch' '-a' '--no-color' '--no-abbrev' '-v'
Failed to initialize global composer: Composer could not find the config file: /home/mortona2k/.composer/composer.json

Reading /var/www/html/vendor/composer/installed.json
Loading plugin Composer\Installers\Plugin (from composer/installers)
Loading plugin cweagans\Composer\Plugin\Patches (from cweagans/composer-patches)
Loading plugin Drupal\Composer\Plugin\Scaffold\Plugin (from drupal/core-composer-scaffold)
Loading plugin Http\Discovery\Composer\Plugin (from php-http/discovery)
Loading plugin PHPCSStandards\Composer\Plugin\Installers\PHPCodeSniffer\Plugin (from dealerdirect/phpcodesniffer-composer-installer)
Loading plugin Nevay\SPI\Composer\Plugin (from tbachert/spi)
Loading plugin PHPStan\ExtensionInstaller\Plugin (from phpstan/extension-installer)
Loading plugin Drupal\Composer\Plugin\ProjectMessage\MessagePlugin (from drupal/core-project-message)
Loading plugin Drupal\Composer\Plugin\RecipeUnpack\Plugin (from drupal/core-recipe-unpack)
Running 2.8.12 (2025-09-19 13:41:59) with PHP 8.4.14 on Linux / 6.8.0-90-generic
Reading /var/www/html/patches.lock.json
Running 2.8.12 (2025-09-19 13:41:59) with PHP 8.4.14 on Linux / 6.8.0-90-generic
Reading ./composer.lock (/var/www/html/composer.lock)
> command: Drupal\Composer\Plugin\Scaffold\Plugin->onCommand
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Reading ./composer.lock (/var/www/html/composer.lock)
Built pool.
Generating rules
Resolving dependencies through SAT
Looking at all rules.

Dependency resolution completed in 0.000 seconds
Nothing to install, update or remove
Generating autoload files
> pre-autoload-dump: Drupal\Composer\Plugin\Scaffold\Plugin->preAutoloadDump
> pre-autoload-dump: Http\Discovery\Composer\Plugin->preAutoloadDump
> pre-autoload-dump: Nevay\SPI\Composer\Plugin->preAutoloadDump
Skipping extra.spi provider "OpenTelemetry\SDK\Common\Configuration\Resolver\SdkConfigurationResolver" for "\OpenTelemetry\SDK\Common\Configuration\Resolver\ResolverInterface", provider not available (open-telemetry/sdk 1.10.0 (extra.spi))
106 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> post-install-cmd: Drupal\Composer\Plugin\Scaffold\Plugin->postCmd
Executing command (/var/www/html/web): git ls-files --error-unmatch '/var/www/html/web//autoload.php'
Executing command (/var/www/html): git rev-parse --show-toplevel
Executing command (/var/www/html): git check-ignore 'vendor'
> post-install-cmd: PHPCSStandards\Composer\Plugin\Installers\PHPCodeSniffer\Plugin->onDependenciesChangedEvent
Running PHPCodeSniffer Composer Installer
Executing command (/var/www/html/vendor/squizlabs/php_codesniffer): '/usr/bin/php8.4' -d allow_url_fopen='1' -d disable_functions='' -d memory_limit='-1' ./bin/phpcs --config-show
No PHPCS standards to install or update
> post-install-cmd: PHPStan\ExtensionInstaller\Plugin->process
phpstan/extension-installer: Extensions installed
> post-install-cmd: Drupal\Composer\Plugin\ProjectMessage\MessagePlugin->displayPostCreateMessage
  * Homepage: https://www.drupal.org/project/drupal
  * Support:
    * docs: https://www.drupal.org/docs/user_guide/en/index.html
    * chat: https://www.drupal.org/node/314178

Seems like it's not finding the patches at all. I tried in a separate composer.patches.json file (defined in extra.patches-file). Also tried with patches.json, which is supposed to be the default.
The config did change between 1 and 2.
In 1, it was:

  "extra": {
    "patches-file": "local/path/to/your/composer.patches.json"
  }

In 2, it's:

    "extra": {
        "composer-patches": {
            "patches-file": "mypatches.json"
        }
    }
mortona2k’s picture

I had problems with a Drupal CMS instance. It was fixed by deleting the ddev instance, trashing the directory, and starting over.

I fixed my drupal11 instance by deleting patches.lock.json, web/core, and running composer install again.

Some combination of ddev rebuild or composer clear-cache may have helped.

cmlara’s picture

Copying messages from Slack that may be useful for others in the future:

Thread: https://drupal.slack.com/archives/C392CHBEW/p1767288647060889

… did you follow https://docs.cweagans.net/composer-patches/usage/recommended-workflows/ and run relock after editing [the composer patches list]?

Does repatch require a patch to already be in the lock file and if not perhaps will not attempt to apply it? Might give you reason as to why it doesn't see your patch.

cilefen’s picture

@vasyok May we see the output of composer install -vvv? I doubt whatever fails is silent in that output.

vasyok’s picture

Applying patches

with composer-patches 1.7.x

In composer.json it is enough to write:

"extra": {
...
        "patches": {
            "drupal/core": {
                "Patch 1 for core": "web/patches/patch_1_for_core.patch"
            },
            "drupal/module1": {
                "Patch 1 for module 1": "web/patches/patch_1_for_module_1.patch",
                "Patch 2 for module 1": "web/patches/patch_1_for_module_2.patch",
            },
            "drupal/module2": {
                "Patch 1 for module 2": "web/patches/patch_1_for_module_2.patch"
            }
        }
...
}

After the patch is written in composer.json, need to run:
composer install

with composer-patches 2.x

In composer.json:

"extra": {
...
        "composer-exit-on-patch-failure": true,
        "patchLevel": {
            "drupal/core": "-p2"
        },
        "patches": {
            "drupal/core": {
                "Patch 1 for core": "web/patches/patch_1_for_core.patch"
            },
            "drupal/module1": {
                "Patch 1 for module 1": "web/patches/patch_1_for_module_1.patch",
                "Patch 2 for module 1": "web/patches/patch_1_for_module_2.patch",
            },
            "drupal/module2": {
                "Patch 1 for module 2": "web/patches/patch_1_for_module_2.patch"
            }
        }
...
}

here:

 "patchLevel": {
            "drupal/core": "-p2"
        },

This is sufficient for most of cases.

After the patch is written in composer.json, need to run:

rm patches.lock.json
composer patches-repatch

Important note.

Composer-patches 2.x applies patches using git apply and requires patches in git diff format.

This means that patches must include the a/ and b/ prefixes in their file paths:

diff --git a/file.name b/file.name
--- a/file.name
+++ b/file.name

Patches without prefixes (--no-prefix), for example

diff --git file.name file.name
--- file.name
+++ file.name

cannot be applied with composer-patches 2.x and will result the error:
No available patcher was able to apply patch.

An example of how to create a patch correctly.

This doesn't necessarily mean it has to be done this way. It can be done differently.

In the module folder:

git init
git add .
git commit -m "Initial commit"

Сopy the modified module files over the original ones, then:

git add .
git diff --cached > patch_1_for_module_1.patch
quietone’s picture

Issue summary: View changes
Status: Active » Fixed

This support request seems to be resolved, it certainly is not a Drupal core issue and there hasn't been discussion for 2 months.

I am closing this per the guidance in Handle or refer a support request in an issue.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.