PSR-4 mapping in composer.json leads to problems in some installs

Created on 8 December 2021, about 3 years ago
Updated 6 April 2023, over 1 year ago

We have a project with "drupal-composer/drupal-scaffold", where contrib modules go to "web/modules/contrib/".
There is a top-level '/src/' directory with classes used for cli operations, mapped to a custom namespace specific to this project.

The entity_meta_relation has a composer.json which maps 'Drupal\\emr\\' to './src'.
For some reason, in vendor/composer/autoload_psr4.php this results in 'Drupal\\emr\\' => array($baseDir . '/src'),.

I imagine this problem could be gone once we move to Drupal 9, and "drupal/core-composer-scaffold", which we are doing right now.

But do we really need this mapping in composer.json for entity_meta_relation?
In general, this should be added automatically by Drupal.

If needed for test runs, the mapping could be added in autoload-dev instead.

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany donquixote

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.

  • 🇫🇷France Julien Tekrane

    This is still an ongoing issue

  • Yes, I can confirm, this is still happening.
    As said by @donquixote , maybe this is not impacting the module itself cause Drupal is able to load it by its own, but it is appearing when including custom namespaces inside a docroot src/ folder.
    Could be this is related to an old renaming of this module from drupal/emr into drupal/entity_meta_relation?

    Thanks in advance.

  • 🇧🇪Belgium keszthelyi Brussels

    I also have the same issue, emr messing up the top level src directory custom project namespace, causing PHP Fatal error: Cannot declare class... errors for certain scripts.

    I digged into the composer autoload generation, and after some debugging, I found that in my case it was not this module that caused the issue, but the fact that this module was a dependency for another module (OE Listing page). That module is requiring a metapackage called 'emr', that doesn't have an install path, because of this an empty string will be used by composer in the packageMap here, and that results in the 'Drupal\\emr\\' => array($baseDir . '/src'), in the autoload file.

    Not sure in what context others have this problem, but after I found this, I installed the module alone (not as a dependency), and could not reproduce the issue anymore.

    I ended up replacing the emr metapackage and requiring entity_meta_relation directly in my project's composer.json to be able to use the module.

  • Hey @keszthelyi could you please confirm, then if requiring drupal/entity_meta_relation you have an entry for it in composer autoload_psr4 or if it is working by being loaded by Drupal itself?
    I guess, then that issue should be reported as an issue about the dependency definition for oe_list_pages.

  • 🇧🇪Belgium keszthelyi Brussels

    Hi @joanpebupe, when requiring drupal/entity_meta_relation directly, then there's no entry in autoload_psr4.php and it's working by being loaded by Drupal. Yes, I'm planning to report this on oe_list_pages.

  • Hi @keszthelyi, I guess then that if oe_lists_pages fixes its dependcy to request drupal/entity_meta_relation instead of drupal/emr that issue could be closed as seems that module (by its own) would be working as expected.

    Issue opened in oe_list_pages side: https://github.com/openeuropa/oe_list_pages/issues/176

Production build 0.71.5 2024