9

I have an issue disabling modules, I've searched but cannot find something useful:
- Developer A disable module and via composer remove it
- I pull his changes so i run composer install that remove the code, then drush cim to update configuration, but it complains that the module is missing while it's trying to delete its configurations.

What's the right way to do this? I can't import config before running composer install because along the uninstalled module there could be also new modules needed for the configuration import.

2 Answers 2

8

You need two consecutive releases for stuff like that.

First release:

Your colleague uninstalls the module and commits the updated config.

If you don't manage your site via config use hook_update_N instead.

/**
 * Uninstall SOME_MODULE module.
 */
function MYMODULE_update_8001(&$sandbox) {

  \Drupal::service('module_installer')->uninstall(['SOME_MODULE']);
}

Second release:

The module can be removed via Composer.


Related:

Order of drush commands for automated deployment?

1
  • A practical note: If the module you are trying to remove has dependencies that were automatically installed via composer, then you need to disable those dependencies as well. Best way to find out is to remove the module via composer, check the list of removed packages, revert the composer change, remove modules, export configuration, first release, then rerun the composer removal part, and second release.
    – pgampe
    Sep 22, 2023 at 12:39
5

Adding an alternative solution to @leymannx - you will still need two releases. This is taking into consideration your mention of drush cim

First release:

  1. Uninstall the module drush pmu module_name
  2. Export the configuration.
  3. Commit, push, and release.
  4. Deploy and execute drush cim. That should uninstall the module.

A hacky way to uninstall is directly editing the core.extension.yml, remove the complete entry of the module from under the module: key, and executing drush cim. NOTE: Use this hacky way only when you are sure that the module doesn't export any configuration. Else, there would be an exception thrown.

Second release:

Removing module from composer.

1
  • Thanks, it seems to me that the accepted answer is more "safe" but this could be helpful. While developing without an actual release online should be ok to speed up and avoid a lot of code, and errors can be handled easily.
    – Francesco
    Oct 19, 2018 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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