Skip to content

Magento cannot run with custom Composer vendor directories #17753

Closed
@vbuck

Description

@vbuck

When using the COMPOSER_VENDOR_DIR setting to specify a vendor path outside of the Magento installation root, Magento's autoloader registration fails to generate the correct path.

Preconditions

  1. Any host with access to two separate parent directories.
  2. Any recent version of composer installed

Steps to reproduce

  1. Create a temporary directory for vendor data: mkdir /tmp/composer-vendor-dir
  2. Create a project directory: mkdir ~/magento-project
  3. Set the Composer vendor directory: export COMPOSER_VENDOR_DIR="/tmp/composer-vendor-dir"
  4. Create a Magento project: composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition ~/magento-project
  5. Observe successful Composer installation
  6. Attempt to access Magento CLI: php bin/magento

Expected result

  1. Using php bin/magento should produce a command list

Actual result

  1. Error message given:
Autoload error: Vendor autoload is not found. Please run 'composer install' under application root directory.

Additional Information

File app/autoload.php incorrectly assumes a vendor path relative to the project:

define('BP', dirname(__DIR__));
...
$vendorAutoload = BP . "/{$vendorDir}/autoload.php";

Which in the example scenario given produces a path like:

  • /home/user/magento-project//tmp/composer-vendor-dir/autoload.php

The validation of $vendorAutoload should be modified to resolve variations of the assembled path, in a way that it can accept an absolute path returned by app/etc/vendor_path.php

Metadata

Metadata

Assignees

Labels

Component: Framework/AppEvent: mm18mxFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions