Error: Class "\Drupal\Component\ComponentDiscovery" not found

Created on 7 July 2022, almost 2 years ago
Updated 8 January 2024, 6 months ago

Problem/Motivation

When attempting to analyze the component module for D10 readiness, it exploded with this error:

[error]  Error: Class "\Drupal\Component\ComponentDiscovery" not found in Drupal\Component\DependencyInjection\Container->createService() (line 262 of /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php) #0 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(176): Drupal\Component\DependencyInjection\Container->createService(Array, 'component.disco...')
#1 /var/www/html/web/core/lib/Drupal.php(197): Drupal\Component\DependencyInjection\Container->get('component.disco...')
#2 /var/www/html/web/modules/contrib/component/component.module(42): Drupal::service('component.disco...')
#3 [internal function]: component_library_info_build()
#4 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(417): call_user_func_array(Object(Closure), Array)
#5 /var/www/html/src/ModuleHandler.php(34): Drupal\Core\Extension\ModuleHandler->invoke('component', 'library_info_bu...', Array)
#6 /var/www/html/web/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php(370): App\ModuleHandler->invoke('component', 'library_info_bu...')

This appears due to fact that the namespace has the incorrect case. Additionally this namespace is used by Drupal core and can cause conflicts later.

Proposed resolution

Change all namespace references to lowercase to conform to Drupal contrib module best practices.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇺🇸United States japerry KVUO

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.

  • 🇧🇷Brazil varod-br São Paulo

    I was still getting this error with 1.0.0-rc4 (Drupal 9.5.9 / PHP 8.1.24):

    Error: Class "Drupal\component\Plugin\Derivative\DeriverBase" not found em include() (line 13 of /docroot/modules/contrib/component/src/Plugin/Derivative/ComponentBlockDeriver.php)
    #0 /vendor/composer/ClassLoader.php(576): include()
    #1 /vendor/composer/ClassLoader.php(427): Composer\Autoload\{closure}('/mnt/www/html/s...')
    #2 [internal function]: Composer\Autoload\ClassLoader->loadClass('Drupal\\componen...')
    #3 /docroot/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php(217): class_exists('Drupal\\componen...')
    #4 /docroot/core/lib/Drupal/Core/Plugin/Discovery/ContainerDerivativeDiscoveryDecorator.php(20): Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDeriverClass(Array)
    #5 /docroot/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php(99): Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator->getDeriver('component', Array)
    #6 /docroot/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php(87): Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDerivatives(Array)
    

    So I created this patch. Maybe it's not right, but due the ambiguity with the project name and the core Component class, it seems to solve the problem.

    Best! (sorry if should be done through a new issue or in other way)

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
Production build 0.69.0 2024