Fatal Error when installing a custom profile containing libraries, which contain functions, all of this via via Drush

Created on 20 September 2016, about 8 years ago
Updated 15 August 2024, 4 months ago

So I understand this is *really* an edge case. I'm more interested in having some information, rather than actually getting it fixed (I can patch it and manage it myself; it must be very rare).

I have a custom installation profile, which includes Libraries API and XAutoload. When installing through the UI (via /install.php), it works fine. However, when installing via Drush (typically the case when using Aegir), it throws a Fatal Error. I tracked it down to Drupal\xautoload\Discovery\ComposerJson::writeToAdapter(). What happens is that a library has some functions, which are included via the composer.json autoload.files directive (library in question: https://github.com/fruux/sabre-xml/). XAutoload, during an install via Drush, actually requires the file containing these functions twice, resulting in the Fatal Error.

A simple fix is changing the require call to a require_once. The installation now passes without problem. But what I'm worried about is: why use require in the first place? Is there any reason for this? If I patch it (example patch will follow soon), will it break my installs down the road?

Thanks for the help.

Feature request
Status

Needs review

Version

5.0

Component

Code

Created by

🇨🇭Switzerland wadmiraal

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • I notice that this issue is ancient, however I've just had a similar issue.

    I used

    function mymodule_xautoload($adapter) {
    $adapter->absolute()->composerDir('../vendor/composer');
    }

    and then I got an error when calling drush (for example drush cc)

    PHP Fatal error: Cannot declare class OpenAI, because the name is already in use in /home/staging/deploy/vendor/openai-php/client/src/OpenAI.php on line 8
    Drush command terminated abnormally due to an unrecoverable error. [error]
    Error: Cannot declare class OpenAI, because the name is already in use in
    /home/staging/deploy/vendor/openai-php/client/src/OpenAI.php, line 8 [0.28 sec, 45.44 MB]

    Changing all the requires to require_once in src/Discovery ComposerJson.php, ComposerDir.php and ComposerJsonTargetDir.php fixed this for me.

Production build 0.71.5 2024