By Mrweiner


2019-06-12 01:22:07 8 Comments

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 ^[email protected] 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": "^[email protected]",
        "drupal/blazy": "^[email protected]",
        "drupal/ckeditor_media_embed": "^1.3",
        "drupal/color_field": "^2.0",
        "drupal/config_inspector": "^[email protected]",
        "drupal/config_update": "^1.6",
        "drupal/console": "~1.0",
        "drupal/context": "^[email protected]",
        "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": "^[email protected]",
        "drupal/ds": "3.x-dev",
        "drupal/entity_clone": "^[email protected]",
        "drupal/entity_print": "^2.1",
        "drupal/entity_update": "^[email protected]",
        "drupal/entity_usage": "^[email protected]",
        "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": "^[email protected]",
        "drupal/imagemagick": "^2.4",
        "drupal/imagick": "^1.2",
        "drupal/imce": "^1.7",
        "drupal/inline_entity_form": "^[email protected]",
        "drupal/languageicons": "^[email protected]",
        "drupal/layout_builder_at": "^2.8",
        "drupal/layout_builder_modal": "^[email protected]",
        "drupal/layout_builder_restrictions": "^2.2",
        "drupal/media_entity": "^2.0",
        "drupal/media_entity_browser": "2.x-dev",
        "drupal/media_entity_generic": "^[email protected]",
        "drupal/media_entity_image_exif": "1.x-dev",
        "drupal/media_entity_video": "^[email protected]",
        "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": "^[email protected]",
        "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": "^[email protected]",
        "drupal/slick": "^[email protected]",
        "drupal/slick_media": "^[email protected]",
        "drupal/slick_paragraphs": "^2.0",
        "drupal/smtp": "^[email protected]",
        "drupal/stage_file_proxy": "^[email protected]",
        "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": "^[email protected]",
        "drupal/views_bulk_operations": "^2.5",
        "drupal/views_data_export": "^[email protected]",
        "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:",
            "https://www.drupal.org/node/2718229"
        ],
        "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"
        }
    ]
}

1 comments

@Jdrupal 2019-09-02 10:20:24

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.

@Mrweiner 2019-09-02 18:26:35

Sorry, that's a custom local patch. This issue was indeed present prior that adding this patch into the mix

@Jdrupal 2019-09-03 07:13:18

Uh, try to take a look at my updated answer. Thanks.

@Mrweiner 2019-09-03 21:53:56

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.

@Jdrupal 2019-09-03 22:12:22

@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!

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] Composer using old JSON for contrib module?

  • 2019-08-16 19:03:43
  • Kieran Mathieson
  • 72 View
  • 1 Score
  • 1 Answer
  • Tags:   composer

1 Answered Questions

[SOLVED] How to include a patch to a JS library?

  • 2019-07-21 15:17:06
  • hepabolu
  • 17 View
  • 0 Score
  • 1 Answer
  • Tags:   8 composer

1 Answered Questions

[SOLVED] How to do core development with composer-based install?

  • 2019-01-07 15:20:32
  • William Turrell
  • 88 View
  • 3 Score
  • 1 Answer
  • Tags:   8 composer

2 Answered Questions

[SOLVED] Why does RELAXed Web Services Not appear in the module list?

  • 2018-05-03 14:54:12
  • James R
  • 128 View
  • 0 Score
  • 2 Answer
  • Tags:   8 composer

1 Answered Questions

[SOLVED] How do I update core to 8.5?

  • 2018-03-31 18:45:55
  • user5950
  • 1052 View
  • 0 Score
  • 1 Answer
  • Tags:   8 updating composer

1 Answered Questions

[SOLVED] How can I upgrade ONLY Drupal core with composer?

  • 2017-08-14 19:12:36
  • RaisinBranCrunch
  • 990 View
  • 4 Score
  • 1 Answer
  • Tags:   8 updating composer

1 Answered Questions

[SOLVED] Is there an automatic way to convert old versioning conventions?

  • 2017-04-09 19:31:17
  • therobyouknow
  • 247 View
  • 0 Score
  • 1 Answer
  • Tags:   8 updating composer

1 Answered Questions

5 Answered Questions

[SOLVED] How to apply patches?

  • 2015-04-29 18:23:52
  • learn4ever
  • 4675 View
  • 1 Score
  • 5 Answer
  • Tags:   7 version-control

Sponsored Content