[drush] Uncaught Exception: Could not locate autoload.php when `vendor/` folder is symlinked
Closed this issue · 5 comments
When executing any drush command, I get this weird exception:
Uncaught Exception: Could not locate autoload.php. cwd is /var/www/html; __DIR__ is /var/www/html/web/vendor/drush/drush
Specifically I'm using:
Host setup : DDEV 1.19
Drupal version : 9.4.0-dev
Drush version : 10.6.2
Drush script : /var/www/html/vendor/bin/drush
When using Xdebug, I can see in order:
- vendor/bin/drush is executed
- vendor/drush/drush/drush is executed
- vendor/drush/drush/drush.php is executed. And vendor/autoload.php is found
- then during executing the command **web/**vendor/drush/drush/drush.php is called, and the autoload.php is not found for some reason.
This is either when I execute drush
or vendor/bin/drush
or vendor/drush/drush/drush
, always from the root of the project /var/www/html
.
What is interesting is that if I get rid of the vendor folder symlink (doc, code) everything works. Drupal can find the autoload.php from the vendor folder on the project root and everything works. 🤔 🤔 🤔
So as I workaround I just have a rm repos/drupal/vendor
added to the post-drupal-scaffold-cmd
scripts.
Hmm that's weird. Drush works for me (apart from drush cr
as documented).
That vendor symlink is only needed to run tests. Normal Drupal operation will work fine without it.
then during executing the command **web/**vendor/drush/drush/drush.php is called, and the autoload.php is not found for some reason.
I presume that's at line 52 of that file?
Can you debug some more to find what the actual paths are that Drush is trying to include?
The correct line is this: https://github.com/drush-ops/drush/blob/10.6.2/drush.php#L58
At that point __DIR__
is /var/www/html/web/vendor/drush/drush
, so drush.php is looking for:
/var/www/html/web/vendor/drush/drush/vendor/autoload.php
/var/www/html/web/vendor/drush/drush/../autoload.php
/var/www/html/web/vendor/drush/drush/../../autoload.php
As mentioned, drush.php is called twice. The first round runs <root>/vendor/drush/drush/drush,php
, the second round <root>/wev/vendor/drush/drush/drush.php
.
This happenswith drush si
and drush status
.
I'll run drush with -vvv to see exactly what is calling drush.php for the second time. Updates soon.
After a newly fresh installation the problem disappeared. Probably something was corrupted locally?
I don't know. What I can see is that the vendor folder is on <root>/vendor
t, symlinked on repos/drupal/vendor
and not appearing in web/
.
Closing this. Thanks @joachim-n .
Phew!
Thanks for investigating and figuring it out! :)