composer: Broken autoload in Magento project after upgrade to 2.5.6

$ composer --version
Composer version 2.5.6 2023-05-24 09:14:18

After the upgrade to composer 2.5.6, I started getting an issue - autoloader became broken after running composer dump-autoload --optimize. Here are steps to reproduce:

$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition test
...
$ cd test/
$ composer install --no-dev
...
$ php bin/magento --version
Magento CLI 2.4.6
$ composer dump-autoload --optimize
Generating optimized autoload files
Generated optimized autoload files containing 880 classes
$ php bin/magento --version

Fatal error: Uncaught Error: Class "Magento\Framework\Component\ComponentRegistrar" not found in /var/www/html/test/setup/src/Magento/Setup/registration.php:9
Stack trace:
#0 /var/www/html/test/app/etc/NonComposerComponentRegistration.php(29): require_once()
#1 [internal function]: Magento\NonComposerComponentRegistration\{closure}('/var/www/html/t...')
#2 /var/www/html/test/app/etc/NonComposerComponentRegistration.php(31): array_map(Object(Closure), Array)
#3 /var/www/html/test/app/etc/NonComposerComponentRegistration.php(34): Magento\NonComposerComponentRegistration\{closure}()
#4 /var/www/html/test/vendor/composer/autoload_real.php(41): require('/var/www/html/t...')
#5 /var/www/html/test/vendor/composer/autoload_real.php(45): {closure}('b4cf39431a4b949...', '/var/www/html/t...')
#6 /var/www/html/test/vendor/autoload.php(25): ComposerAutoloaderInitbb42076190ede96daffb0f7e2039b934::getLoader()
#7 /var/www/html/test/app/autoload.php(51): include('/var/www/html/t...')
#8 /var/www/html/test/app/bootstrap.php(44): require_once('/var/www/html/t...')
#9 /var/www/html/test/bin/magento(14): require('/var/www/html/t...')
#10 {main}
  thrown in /var/www/html/test/setup/src/Magento/Setup/registration.php on line 9

after rolling back to previous composer version:

$ composer dump-autoload --optimize
Generating optimized autoload files
Generated optimized autoload files containing 22510 classes
$ php bin/magento --version
Magento CLI 2.4.6

This issue will affect all (or almost all) Magento2-based projects. Pay attention that the new version generated autoload files for 880 classes only, while the older one was 22510.

And I expected this to happen: No regression issues during composer updates

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 17 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Great, thanks for helping out debugging and testing, that helped a ton!

Thanks for the quick response on this @Seldaek. I have tested with #11481 and confirm that I’m getting the expected auto-loader content in all scenarios listed in https://github.com/composer/composer/issues/11480#issuecomment-1561081728. 👍

@adri I don’t think it’s architecture-dependent. I see this both on Github Actions (where amd64) and on M1 mac in Docker (arm64)