Date Published: March 26, 2025
Cannot declare class ComposerAutoloaderInitDrupal
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:
rm -rf vendor composer.lock
composer update --lock
Did not find what you were looking for?
If this content did not answer your questions, try searching or contacting our support team for further assistance.