Problem/Motivation
I'm getting the following error when running updates:
Error: Call to a member function getPath() on null in /var/www/html/docroot/core/lib/Drupal/Core/Template/Loader/FilesystemLoader.php on line 44 #0 [internal function]: Drupal\Core\Template\Loader\FilesystemLoader->__construct('.', Object(Drupal\Core\Extension\ModuleHandler), Object(Drupal\Core\Extension\Theme
Handler), Array)
> #1 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(1142): ReflectionClass->newInstanceArgs(Array)
> #2 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(618): Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object(Symfony\Component\DependencyInjection\Definition), Array, false, 'twig.loader.fil...')
> #3 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(1265): Symfony\Component\DependencyInjection\ContainerBuilder->doGet('twig.loader.fil...', 1, Array, false)
> #4 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(1213): Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices(Object(Symfony\Component\DependencyInjection\Reference), Array, false)
> #5 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(1621): Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices(Array, Array)
> #6 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(1167): Symfony\Component\DependencyInjection\ContainerBuilder->callMethod(Object(Twig\Loader\ChainLoader), Array, Array)
> #7 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(1267): Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object(Symfony\Component\DependencyInjection\Definition), Array, true)
> #8 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(1213): Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices(Object(Symfony\Component\DependencyInjection\Definition), Array, true)
> #9 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(1115): Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices(Array, Array, true)
> #10 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(618): Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object(Symfony\Component\DependencyInjection\Definition), Array, true, 'twig')
> #11 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(558): Symfony\Component\DependencyInjection\ContainerBuilder->doGet('twig', 1)
> #12 /var/www/html/docroot/core/lib/Drupal.php(207): Symfony\Component\DependencyInjection\ContainerBuilder->get('twig')
> #13 /var/www/html/docroot/core/includes/common.inc(559): Drupal::service('twig')
> #14 /var/www/html/vendor/drush/drush/src/Commands/core/UpdateDBCommands.php(543): drupal_flush_all_caches()
> #15 /var/www/html/vendor/drush/drush/includes/batch.inc(261): Drush\Commands\core\UpdateDBCommands::cacheRebuild(Object(DrushBatchContext))
> #16 /var/www/html/vendor/drush/drush/includes/batch.inc(206): _drush_batch_worker()
> #17 /var/www/html/vendor/drush/drush/includes/batch.inc(100): _drush_batch_command('11')
> #18 /var/www/html/vendor/drush/drush/src/Commands/core/UpdateDBCommands.php(175): drush_batch_command('11')
> #19 [internal function]: Drush\Commands\core\UpdateDBCommands->process('11', Array)
> #20 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
> #21 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
> #22 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
> #23 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(350): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
> #24 /var/www/html/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #25 /var/www/html/vendor/symfony/console/Application.php(1039): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #26 /var/www/html/vendor/symfony/console/Application.php(275): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #27 /var/www/html/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #28 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #29 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(48): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
> #30 /var/www/html/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
> #31 /var/www/html/vendor/drush/drush/drush(3): require('/var/www/html/v...')
> #32 /var/www/html/bin/drush(115): include('/var/www/html/v...')
> #33 {main}
> PHP Fatal error: Uncaught Error: Call to a member function getPath() on null in /var/www/html/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php:728
> Stack trace:
> #0 /var/www/html/docroot/core/lib/Drupal/Core/Routing/RouteBuilder.php(234): Drupal\Core\Extension\ModuleHandler->getModuleDirectories()
> #1 /var/www/html/docroot/core/lib/Drupal/Core/Routing/RouteBuilder.php(135): Drupal\Core\Routing\RouteBuilder->getRouteDefinitions()
> #2 /var/www/html/docroot/core/lib/Drupal/Core/Routing/RouteBuilder.php(210): Drupal\Core\Routing\RouteBuilder->rebuild()
> #3 /var/www/html/docroot/core/lib/Drupal/Core/Routing/RouteBuilder.php(222): Drupal\Core\Routing\RouteBuilder->rebuildIfNeeded()
> #4 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php(51): Drupal\Core\Routing\RouteBuilder->destruct()
> #5 [internal function]: Drupal\Core\EventSubscriber\KernelDestructionSubscriber->onKernelTerminate(Object(Symfony\Component\HttpKernel\Event\TerminateEvent), 'kernel.terminat...', Object(Drupal\Component\Event in /var/www/html/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php on line 728
Steps to reproduce
It's not easy to replicate. I'm using a multisite and the error happens only for one of the sites.
Proposed resolution
Check if $extension is not null.