Have you ever tried to uninstall a Magento 2 module using the bin/magento module:uninstall ModuleProvider_ModuleName
and after running the bin/magento setup:upgrade
it always seems to re-enable itself? Well, you’re not alone.
*This is only applicable to Magento 2 modules that you installed using composer.
When you uninstall the module using the method above, it only removes the module entry inside the app/etc/config.php file and the composer.json file. It doesn’t remove the module information from the composer.lock file. The module will be reinstalled and re-enabled when you run a composer install at a later date. In order to completely remove the module you have to the following commands.
First you need to check to see if the module is enabled. You also get the “ModuleProvider_ModuleName” from this output:
bin/magento module:status
Next, you disable the module:
bin/magento module:disable ModuleProvider_ModuleName --clear-static-content
I always run the following to make sure that the module is disabled in the config.php file, but you can skip this step if you wish:
bin/magento setup:upgrade
Now you remove the module from the composer.json and composer.lock files:
composer remove VendorName/VendorRepository
*The VendorName/VendorRepository is a different value than what you used above to disable the module (ModuleProvider_ModuleName). To get the VendorName/VendorRepository value just check in the composer.json file. You could also check inside your vendor folder for this value, e.g. MagentoRoot/vendor/jamersan/module-reviews
Finally, run through the setup process and it will remove the entry from all appropriate files.
bin/magento setup:upgrade
Note: Depending on if you have cache enabled or if you are in developer or production mode, you may need to run through a few extra steps to deploy static content and flush the Magento caches:
If you are in Production mode: bin/magento deploy:mode:set production
If you are in Developer mode: bin/magento c:f
bin/magento c:c
That’s it! You no longer have to worry about a module re-installing or re-enabling whenever you run through a deployment process.