Description
When installing Magento to a root level directory (e.g. /magento
) the files generated by Composer contain invalid paths and result in the inability to load Magento\Framework\Component\ComponentRegistrar
, bricking the application.
This was discovered when installing Magento into a top level directory inside of a docker container.
The problem appears to be in the generated vendor/composer/autoload_static.php
file. The $files
property has duplicated file prefixes, e.g:
public static $files = array (
'07ec02c7e667fdcb3e30c02cc772b743' => __DIR__ . '/..' . __DIR__ . '/../..' . '/framework/registration.php',
'3d9d6f82d2fa20ee6036e230ae5c2fff' => __DIR__ . '/..' . __DIR__ . '/../..' . '/module-ui/registration.php',
'fbcc86ec9185efc54c1e806bbb33c954' => __DIR__ . '/..' . __DIR__ . '/../..' . '/module-store/registration.php',
I'd expect these lines to look like the following (and they do, when not using a stupid directory):
public static $files = array (
'07ec02c7e667fdcb3e30c02cc772b743' => __DIR__ . '/..' . '/magento/framework/registration.php',
'3d9d6f82d2fa20ee6036e230ae5c2fff' => __DIR__ . '/..' . '/magento/module-ui/registration.php',
'fbcc86ec9185efc54c1e806bbb33c954' => __DIR__ . '/..' . '/magento/module-store/registration.php',
This may very well be a problem with composer, but I'd like to confirm that Magento isn't doing something to the autoload map generation before heading over there.
Steps to reproduce
Tested with PHP 7.0.3 and 7.0.7:
composer create-project --repository-url=https://repo.magento.com/ \
magento/project-community-edition \
/magento
chmod +x /magento/bin/magento
/magento/bin/magento list
Expected result
Magento CLI version 2.0.7
Usage:
command [options] [arguments]
Options:
--help (-h) Display this help message
... trimmed out some commands ...
setup:performance:generate-fixtures Generates fixtures
setup:rollback Rolls back Magento Application codebase, media and database
setup:store-config:set Installs the store configuration
setup:uninstall Uninstalls the Magento application
setup:upgrade Upgrades the Magento application, DB data, and schema
Actual result
PHP Fatal error: Uncaught Error: Class 'Magento\Framework\Component\ComponentRegistrar' not found in /magento/vendor/magento/framework/registration.php:7
Stack trace:
#0 /magento/vendor/composer/autoload_real.php(71): require()
#1 /magento/vendor/composer/autoload_real.php(61): composerRequire88e4545d1b520c2793b1dd2b497ba4e0('07ec02c7e667fdc...', '/magento/vendor...')
#2 /magento/vendor/autoload.php(7): ComposerAutoloaderInit88e4545d1b520c2793b1dd2b497ba4e0::getLoader()
#3 /magento/app/autoload.php(21): include('/magento/vendor...')
#4 /magento/app/bootstrap.php(30): require_once('/magento/app/au...')
#5 /magento/bin/magento(15): require('/magento/app/bo...')
#6 {main}
thrown in /magento/vendor/magento/framework/registration.php on line 7
Fatal error: Uncaught Error: Class 'Magento\Framework\Component\ComponentRegistrar' not found in /magento/vendor/magento/framework/registration.php:7
Stack trace:
#0 /magento/vendor/composer/autoload_real.php(71): require()
#1 /magento/vendor/composer/autoload_real.php(61): composerRequire88e4545d1b520c2793b1dd2b497ba4e0('07ec02c7e667fdc...', '/magento/vendor...')
#2 /magento/vendor/autoload.php(7): ComposerAutoloaderInit88e4545d1b520c2793b1dd2b497ba4e0::getLoader()
#3 /magento/app/autoload.php(21): include('/magento/vendor...')
#4 /magento/app/bootstrap.php(30): require_once('/magento/app/au...')
#5 /magento/bin/magento(15): require('/magento/app/bo...')
#6 {main}
thrown in /magento/vendor/magento/framework/registration.php on line 7
Known workarounds
- Don't be an idiot. Don't use a root level directory! 🤔