I keep running into the issue that, when requiring a new module with composer, existing packages are removed and reinstalled if they have patches defined in composer.json. For instance:

$ lando composer require drupal/media_entity_browser
    1/2:        https://packages.drupal.org/8/drupal/provider-2019-2$bae9fca7243956d61e44a716bdfb5c872f0f3e1a0b48b1dccfcae53d7e59c86f.json 
    2/2:        https://packages.drupal.org/8/drupal/provider-2019-1$25356ca628b704d49a0ea504e6374f921a2b54d845d142aae1708cb94088516f.json 
    Finished: success: 2, skipped: 0, failure: 0, total: 2
    1/2:        http://repo.packagist.org/p/provider-latest$56447e2294826167894155c32ceb596c58b3b2af059facd78694060f8a4d8c1c.json 
    2/2:        http://repo.packagist.org/p/provider-2019-04$a612146345a708aa360ee61a695dd52d8d0faa79e136de5e075c95860af7c956.json 
    Finished: success: 2, skipped: 0, failure: 0, total: 2
Using version ^1.0@beta for drupal/media_entity_browser 
./composer.json has been updated 
Gathering patches for root package. 
Removing package drupal/core so that it can be re-installed and re-patched. 
  - Removing drupal/core (8.7.3)
Deleting web/core - deleted 
> DrupalProject\composer\ScriptHandler::checkComposerVersion 
Loading composer repositories with package information 
Updating dependencies (including require-dev) 
    1/4:        https://ftp.drupal.org/files/projects/media_entity-8.x-1.8.zip 
    2/4:        https://ftp.drupal.org/files/projects/entity-8.x-1.0-rc3.zip 
    3/4:        https://ftp.drupal.org/files/projects/entity_browser-8.x-2.1.zip 
    4/4:        https://ftp.drupal.org/files/projects/media_entity_browser-8.x-1.0-beta3.zip 
    Finished: success: 4, skipped: 0, failure: 0, total: 4
Package operations: 5 installs, 0 updates, 0 removals 
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute

For something like drupal/core this is really a problem on my local as it takes a while to download and reinstall the package. I can't seem to find a pattern. Sometimes it seems that the repatched package is a requirement of the one being required, other times they are unrelated or no packages are repatched at all.

Has anybody else come across this? Is there a way around it? Ideally we'd only re-apply patches to a package when it's updated.

Here's my composer.json since it was requested:

    "name": "drupal/drupal",
    "description": "Drupal is an open source content management platform powering millions of websites and applications.",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "require": {
        "composer/installers": "^1.0.24",
        "cweagans/composer-patches": "^1.6",
        "drupal/address": "^1.4",
        "drupal/addtoany": "^1.10",
        "drupal/admin_toolbar": "^1.26",
        "drupal/antibot": "^1.2",
        "drupal/better_exposed_filters": "^3.0@alpha",
        "drupal/blazy": "^2.0@beta",
        "drupal/ckeditor_media_embed": "^1.3",
        "drupal/color_field": "^2.0",
        "drupal/config_inspector": "^1.0@beta",
        "drupal/config_update": "^1.6",
        "drupal/console": "~1.0",
        "drupal/context": "^4.0@beta",
        "drupal/core": "^8.7.0",
        "drupal/csv_serialization": "^1.4",
        "drupal/ctools": "^3.2",
        "drupal/delete_all": "^1.0",
        "drupal/devel": "^2.0",
        "drupal/draggableviews": "^1.2",
        "drupal/dropzonejs": "^2.0@alpha",
        "drupal/ds": "3.x-dev",
        "drupal/entity_clone": "^1.0@beta",
        "drupal/entity_print": "^2.1",
        "drupal/entity_update": "^1.2@RC",
        "drupal/entity_usage": "^2.0@alpha",
        "drupal/features": "^3.8",
        "drupal/file_mdm": "^1.1",
        "drupal/form_options_attributes": "^1.0",
        "drupal/geocoder": "^2.0",
        "drupal/geofield_map": "^2.23",
        "drupal/google_analytics": "^3.0",
        "drupal/google_tag": "^1.1",
        "drupal/honeypot": "^1.29",
        "drupal/htmlmail": "^3.0@alpha",
        "drupal/imagemagick": "^2.4",
        "drupal/imagick": "^1.2",
        "drupal/imce": "^1.7",
        "drupal/inline_entity_form": "^1.0@RC",
        "drupal/languageicons": "^1.0@beta",
        "drupal/layout_builder_at": "^2.8",
        "drupal/layout_builder_modal": "^1.0@alpha",
        "drupal/layout_builder_restrictions": "^2.2",
        "drupal/media_entity": "^2.0",
        "drupal/media_entity_browser": "2.x-dev",
        "drupal/media_entity_generic": "^1.0@alpha",
        "drupal/media_entity_image_exif": "1.x-dev",
        "drupal/media_entity_video": "^2.0@alpha",
        "drupal/menu_export": "^1.2",
        "drupal/menu_per_role": "^1.0",
        "drupal/metatag": "^1.8",
        "drupal/migrate_plus": "^4.1",
        "drupal/migrate_source_csv": "^2.2",
        "drupal/migrate_tools": "^4.1",
        "drupal/panelbutton": "^1.2",
        "drupal/paragraphs": "^1.5",
        "drupal/path_redirect_import": "^1.0@beta",
        "drupal/pathauto": "^1.3",
        "drupal/permissions_by_term": "^2.10",
        "drupal/recaptcha": "^2.4",
        "drupal/redirect": "^1.3",
        "drupal/redis": "^1.1",
        "drupal/rename_admin_paths": "^1.1",
        "drupal/restrict_ip": "^1.3",
        "drupal/search_api": "^1.12",
        "drupal/search_api_autocomplete": "^1.2",
        "drupal/search_api_page": "^1.0@alpha",
        "drupal/slick": "^2.0@beta",
        "drupal/slick_media": "^2.0@alpha",
        "drupal/slick_paragraphs": "^2.0",
        "drupal/smtp": "^1.0@beta",
        "drupal/stage_file_proxy": "^1.0@alpha",
        "drupal/superfish": "^1.3",
        "drupal/taxonomy_menu": "^3.4",
        "drupal/tmgmt": "^1.7",
        "drupal/twig_tweak": "^2.1",
        "drupal/views_accordion": "^1.2",
        "drupal/views_block_area": "^1.0@beta",
        "drupal/views_bulk_operations": "^2.5",
        "drupal/views_data_export": "^1.0@beta",
        "drupal/webform": "5.1",
        "drupal/weight": "^3.1",
        "drush/drush": "^9.2",
        "league/iso3166": "^2.1",
        "solarium/solarium": "3.8",
        "wikimedia/composer-merge-plugin": "^1.4"
    "require-dev": {
        "webflo/drupal-core-require-dev": "^8.7.0"
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "preferred-install": "dist",
        "autoloader-suffix": "Drupal8",
        "sort-packages": true
    "conflict": {
      "doctrine/common": ">2.8"
    "extra": {
        "_readme": [
            "By default Drupal loads the autoloader from ./vendor/autoload.php.",
            "To change the autoloader you can edit ./autoload.php.",
            "This file specifies the packages.drupal.org repository.",
            "You can read more about this composer repository at:",
        "installer-paths": {
            "core": ["type:drupal-core"],
            "modules/contrib/{$name}": ["type:drupal-module"],
            "profiles/contrib/{$name}": ["type:drupal-profile"],
            "themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/contrib/{$name}": ["type:drupal-drush"],
            "modules/custom/{$name}": ["type:drupal-custom-module"],
            "themes/custom/{$name}": ["type:drupal-custom-theme"]
        "patches": {
            "drupal/core": {
                "Compatibility with JSON:API": "https://www.drupal.org/files/issues/2018-09-20/2942975-24.patch",
                "Layout builder revisions": "https://www.drupal.org/files/issues/2019-06-06/3033516-8.drupal.Revision-UI-on-Layout-Builder-does-not-function-correctly.patch",
                "Error: Call to a member function getLabel() after enable layout_builder": "https://www.drupal.org/files/issues/2018-07-16/2985882-entityfield-2.patch",
                "media_bundle shim": "patches/295028764_media-bundle-shim.patch"
            "drupal/dropzonejs": {
                "The 'media_bundle' entity type does not exist.": "https://www.drupal.org/files/issues/2019-04-25/2820183-19.patch"
            "drupal/paragraphs": {
                "Paragraphs Translation": "https://www.drupal.org/files/issues/2018-12-14/experimental-widget-asymetric-translation-2904705-47.patch"
            "drupal/entity_reference_revisions": {
                "Fixes broken revisioning on paragraph updates": "https://www.drupal.org/files/issues/2019-01-29/3025709-3.patch"
            "drupal/permissions_by_term": {
                "Use custom 403 destination set by admin form": "https://www.drupal.org/files/issues/2018-11-27/3009470-403-url-settings-ignored-10.patch"
    "autoload": {
        "psr-4": {
            "Drupal\\Core\\Composer\\": "core/lib/Drupal/Core/Composer"
    "scripts": {
        "pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
        "post-autoload-dump": "Drupal\\Core\\Composer\\Composer::ensureHtaccess",
        "post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
        "post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
        "drupal-phpunit-upgrade-check": "Drupal\\Core\\Composer\\Composer::upgradePHPUnit",
        "drupal-phpunit-upgrade": "@composer update phpunit/phpunit --with-dependencies --no-progress",
        "phpcs": "phpcs --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --",
        "phpcbf": "phpcbf --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --"
    "repositories": [
            "type": "composer",
            "url": "https://packages.drupal.org/8"
  • Isn't this a Composer issue for SO? "Don't re-apply patches when requiring new dependency?" Drupal seems to be a coincidence, no? – leymannx Sep 3 '19 at 9:42
  • @leymannx hmm, yeah that's a good point. I think I've only seen it when requiring Drupal packages but I don't know for certain whether or not it's strictly related to Drupal packages – Mrweiner Sep 3 '19 at 17:40

The problem is probably caused because one of the core patches that you are trying to apply doesn't exist or couldn't be downloaded.

I have tested with your composer.json on a clean Drupal 8 install. When running composer update I get the following error:

Could not apply patch! Skipping. The error was: The "patches/295028764_media-bundle-shim.patch" file could not be downloaded: failed to open stream: No such file or directory.

I figured that the media-bundle-shim.patch patch is no longer available, so I removed it from composer.json. After that everything worked fine and it stopped re-applying the core patches every time.

So all you have to do is to remove the patch from composer.json, or replace it with a new one that exists:

"drupal/core": {
  "Compatibility with JSON:API": "https://www.drupal.org/files/issues/2018-09-20/2942975-24.patch",
  "Layout builder revisions": "https://www.drupal.org/files/issues/2019-06-06/3033516-8.drupal.Revision-UI-on-Layout-Builder-does-not-function-correctly.patch",
  /* Remove the last comma from this line. */ "Error: Call to a member function getLabel() after enable layout_builder": "https://www.drupal.org/files/issues/2018-07-16/2985882-entityfield-2.patch",
  /* Remove this line. */"media_bundle shim": "patches/295028764_media-bundle-shim.patch"

UPDATE: The media_bundle patch could not be applyed for me, because it is a local patch.

I thave two suggestions to why it keeps re-applying the patches:

  1. lando causes the issue.
  2. The issue is caused because the local patch is not applied properly.

Since you mention that the issue was there prior to adding the local patch, it's unlikely that it's because the local patch is not being applied properly. I think the problem is lando, since your composer.json file works fine on a clean Drupal install using only Drupal and composer.

I don't know if it is possible to run composer require without lando on your site, but if it's possible you can test if lando is the problem by running composer require without lando.

If that doesn't work, try to remove the local patch to se if the problem persists. Local patch problems.

Hope this helps you debug further.

  • Sorry, that's a custom local patch. This issue was indeed present prior that adding this patch into the mix – Mrweiner Sep 2 '19 at 18:26
  • Uh, try to take a look at my updated answer. Thanks. – user72672 Sep 3 '19 at 7:13
  • the local patch applies fine, it's not the problem. I'm on windows so without going through the rigamarole of setting up php/composer to run outside of lando I'm afraid I cannot test composer outside of it. Tbh I was hoping somebody would come across this who had experienced my same problem but it may be more isolated to my environment than I expected it to be. – Mrweiner Sep 3 '19 at 21:53
  • @Mrweiner I think so, as I say I have tested using php and composer and it works fine. So the problem is probably not drupal. I’m sorry to say but I think this question is a bit off topic here, and should be posted in a lando forum. It’s hard to debug further when we don’t have access to your environment. Hope you got a bit more cleaver on your problem ;) Good luck! – user72672 Sep 3 '19 at 22:12

I think you may miss 2 "extra" settings in your composer.json:

"enable-patching": true,
"patchLevel": {
    "drupal/core": "-p2"


From the composer-patches documentation:

If you want your project to accept patches from dependencies, you must have the following in your composer file: "enable-patching": true

Also the drupal/core": "-p2" avoids things ending up in core/core or core/b. See drupal-project/composer.json and Patch Drupal core without things ending up in core/core or core/b.

  • Unfortunately that didn't help me to avoid drupal/core re-installig/re-patching during simple composer install. But the info about pathLevel was very helpful/useful to correctly patch the core. – Vertigo Apr 15 '20 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.