Cannot declare class ComposerAutoloaderInitDrupal | Acquia Product Documentation
Cloud Platform
Cannot declare class ComposerAutoloaderInitDrupal
Cannot declare class ComposerAutoloaderInitDrupal
Date Published: March 26, 2025
If you modified the composer.json that comes with Drupal and then moved it above the docroot, you may see the following error when attempting to run Drush commands:
Error: Cannot declare class ComposerAutoloaderInitDrupal, because the name is already in use in /mnt/www/html/<site_name>/docroot/vendor/composer/autoload_real.php, line 5
This is a result of the following line that is added to docroot/vendor/autoload.php as well as the vendor/autoload.php that exists above the docroot.
return ComposerAutoloaderInitDrupal::getLoader();
You'll need to remove the following from your composer.json file:
"autoloader-suffix": "Drupal"
You should then delete the composer.lock and vendor directory that exist above the docroot and rebuild them with: