22

I am getting the following error in a Drupal 8 site.

The following module is missing from the file system

It looks as if a custom module was installed and deleted without uninstalling it.

How can I fix this error?

4
  • Are you using the configuration management in the site? Commented Sep 12, 2017 at 20:06
  • Yes I am using that Commented Sep 12, 2017 at 20:09
  • Some advance with the problem? I want to know at the end how do you solve the problem, this can arrive me too in any project. Commented Sep 15, 2017 at 16:34
  • In Drupal 8.7.3 I am getting "following module is missing from the file system: php in drupal_get_filename()" but when I try install the php module I get an error about it already existing in core. The error is preventing me from uninstalling anything. Yesterday I upgraded to 8.7.3 and today to 8.5.3 and cannot shake the error. Cache has been cleared each time and all modules that I know about have been restored. I see notes about Drush but how to install it on 8.7.3? Commented Jun 6, 2019 at 3:20

7 Answers 7

25

Drush 9

drush cdel core.extension module.MYMODULE 
4
  • 3
    Thanks for the answer. It might be helpful to add a bit more explanation about config:delete and maybe use config:delete rather than the cryptic cdel. I think this also works for Drush 10. Commented Jul 29, 2021 at 20:08
  • Worked for me on a Drupal 9 instance. Commented Sep 1, 2021 at 6:55
  • This actually worked for me on a drupal 8.8 migration. Ty! Commented Mar 15, 2022 at 15:26
  • worked for me on d Drupal 10 instance! Commented Jan 31, 2024 at 1:28
19

Assuming you have deleted an unimportant custom module which doesn't need any uninstall routine to be triggered, you can use the following Drush command.

  • Drupal 7

    drush sql-query "DELETE from system where type = 'module' AND name = 'MYMODULE';" 
  • Drupal 8

    drush sql-query "DELETE FROM key_value WHERE collection='system.schema' AND name='MYMODULE';" 

See How to fix "The following module is missing from the file system..." warning messages for more info and alternatives.

2
  • 1
    I tried few times and this for D8 doesnt work at least for d8.7. I would recommend solution below with generating dummy module and then uinstalling. Commented Jun 23, 2019 at 8:22
  • The Drupal 8 command worked for me for a Drupal 9.3.9 upgrade from 8. Commented Apr 1, 2022 at 15:26
14

If you have Drupal Console then a quick way to fix this is to generate a module with the same machine name, then uninstall it.

$ drupal generate:module 

Then type the machine name at the appropriate prompt and accepts defaults for everything else.

$ drush pm-uninstall 

Then you can delete the newly generated module from the file system and continue with your day.

(NB you may find need to keep that generated module, else the error will return. In that case, if you need to install a contrib module with the same name, remove the generated module after adding the contrib module. Then clear the cache.)

3
  • 2
    This was the simplest option after the SQL query above wouldn't work. Commented Oct 19, 2018 at 17:36
  • It helped to resolve my error for module not found. Commented Dec 11, 2019 at 14:36
  • If anyone needs help installing Drupal Console, I found this page helpful. Bear in mind, you'll want to install the Drupal Console Launcher globally, AND the Drupal Console locally (in the project root of your Drupal install). Commented Apr 23, 2020 at 1:44
5

The way I fixed it was by using drush and composer. Get the module with require, install and uninstall with drush then remove with composer.

composer require drupal/missing_module drush en missing_module drush pmu missing_module composer remove drupal/missing_module 

! The step with drush en probably is not nessesary

4

Now with the Configuration Management module the modules configuration is stored in the core.extension.yml file.

Go to edit the file and try to find the missing module from the filesystem then delete the line and import the config (drush cim).

If this not works but you has found the module, then create the module again (just the folder and a valid .info.yml file) and run again the drush cim command. This will uninstall the module.

3
  • 4
    This works, but the correct way is to restore the module and uninstall it. If that module provides schemas, configuration or so, it will remain in the system and you will have to clean it up manually otherwise. Commented Sep 13, 2017 at 6:19
  • 1
    @Berdir if you can't find the custom module, we can do another thing? Commented Sep 13, 2017 at 13:01
  • Not really, then you need to do it manually as suggested above with drush cedit or import/export in the core.extension file. Commented Sep 13, 2017 at 13:18
0

One of the biggest headaches involved with this is getting code to production. Certainly, when deploying to prod, you'll either need to do a layered approach to the deployment (one tag for uninstalling the module and one for removing it from the codebase), however when running ci builds, that's not always easy. I have a script that I just finished that helps cover most of your bases if you need ci to complete successfully when developing with a branch that has a module removed but uses the upstream prod database sync for ci testing.

First, it diffs between active core.extension and the file you have in the repo, then it tries installing via composer (only works for drupal config modules that use proper naming conventions), then it runs the sql-query command (which doesn't always work) and the php:eval command (which works far more often than cdel in these situations).

Since these database changes aren't going to production and are only being used for various unit tests, we have found this is sufficient for most of the work we do. If there are still issues, then we fall back to doing two releases, one for uninstalling the configuration and one for uninstalling from the codebase.

build_message "Detecting deleted modules or themes..." deleted_modules=$(${command_prefix}drush cget core.extension --format=yaml | diff -uw - config/$BUILD_CONFIGURATION_FOLDER/core.extension.yml | grep -v '^@@' | grep '^-\s') module_names=($(echo "$deleted_modules" | awk -F': 0' '{print $1}' | sed 's/^- *//' | grep -v '^[[:space:]]*$')) if [ ${#module_names[@]} -gt 0 ]; then build_message "The script has detected modules deleted in $BUILD_CONFIGURATION_FOLDER which still exist in active configuration: $(IFS=', '; echo "${module_names[*]}") These need to be installed then uninstalled in order for config import to run successfully." BUILD_ERRORS+=" - Deleted modules detected.\n" for module in "${module_names[@]}"; do build_message "Attempting to install and uninstall missing module, $module. This may fail if it is not a Drupal contributed module and will likely fail if it is a theme." composer require drupal/$module --ansi # handle error if it can't install exit_code=$? if [ $exit_code -ne 0 ]; then build_message "Could not install/uninstall missing module $module." warning BUILD_ERRORS+=" - $module could not be installed and uninstalled.\n" build_message "Attempting to uninstall via sql-query instead..." ${command_prefix}drush sql-query "DELETE FROM key_value WHERE collection='system.schema' AND name='$module';" ${command_prefix}drush php:eval "\Drupal::configFactory()->getEditable(\"core.extension\")->clear(\"module.$module\")->save(TRUE);" continue fi ${command_prefix}drush cr ${command_prefix}drush pmu $module composer remove drupal/$module --ansi done git checkout composer.* composer install ${command_prefix}drush cr else build_message "No deleted modules or themes detected!" fi 
-2

if you know exactely what you're doing and can't use a cleaner method from https://www.drupal.org/docs/updating-drupal/troubleshooting-database-updates

here is a suggestion :

drush php:eval '\Drupal::configFactory()->getEditable("core.extension")->clear("module.MY_MODULE_THAT_BREAKS_THINGS")->save(TRUE);' drush cr 
1
  • 4
    If you're going to use drush, why do this instead of config:delete? Commented Jul 29, 2021 at 21:46

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.