Reinstalling a moved module throws “ InvalidArgumentException: Class "\Drupal\example\Form\ExampleForm" does not exist. in Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition()”

Created on 17 February 2023, over 2 years ago
Updated 4 August 2023, almost 2 years ago

Problem/Motivation

After moving a custom module with a form from modules/contrib to modules/custom I got an InvalidArgumentException error.

  • Drupal 10
  • Drush 11
  • Lando 3.11

Steps to reproduce

  1. Install a custom module in modules/contrib (possibly with a form, to trigger the error?)
  2. Uninstall the module with drush un example
  3. Move it to modules/custom
  4. Clear caches with drush cache:rebuild
  5. Install the module
  6. See the error below when trying to access a path registered in the router file

The website encountered an unexpected error. Please try again later.

InvalidArgumentException: Class "\Drupal\example\Form\ExampleForm" does not exist. in Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition() (line 24 of core/lib/Drupal/Core/DependencyInjection/ClassResolver.php).

Drupal\Core\Controller\HtmlFormController->getFormObject(Object, '\Drupal\example\Form\ExampleForm') (Line: 58)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 681)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

The solution

I restarted Lando, after finding InvalidArgumentException: Class ... does not exist in custom configuration form [closed]. The custom module then works, in the modules/custom folder.

I wonder if this is a Drupal 10, Drush 11 or Docker bug? It happens both in Lando and docker4drupal.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Cache 

Last updated 12 days ago

Created by

🇩🇰Denmark ressa Copenhagen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024