Dependencies in submodules are not taken into account

Created on 11 April 2025, about 1 month ago

Problem/Motivation

Quick description
If a submodule of a Drupal module has a dependency declared in its composer.json GitLab CI doesn't download it in the composer step. This can lead to errors on phpstan because some classes from that dependency are not available.

Detailed description with an example

Take the module Image Style Generator. It has a "image_styles_generator_web" submodule that depends on the module WebP.

If I declare in the composer.json of the that submodule the dependency on webp, GitLab CI doesn't download WebP and phpstan complains because it can't find the WebP class it uses. See:

The error is:

 ------ ------------------------------------------------------------------------ 
  Line   modules/image_styles_generator_webp/src/DerivativeWebpWarmer.php        
 ------ ------------------------------------------------------------------------ 
  31     Parameter $webp of method                                               
         Drupal\image_styles_generator_webp\DerivativeWebpWarmer::__construct()  
         has invalid type Drupal\webp\Webp.                                      
 ------ ------------------------------------------------------------------------ 

However, I if add webp as a dependeny in the composer.json of the root folder of the module errors dissappear:

Steps to reproduce

Probaly rerunning the mentioned jobs.

Proposed resolution

I guess composer.json files of submodules should be taken into account.

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

🐛 Bug report
Status

Active

Component

gitlab-ci

Created by

🇪🇸Spain tunic Madrid

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

Comments & Activities

  • Issue created by @tunic
  • 🇬🇧United Kingdom jonathan1055

    Hi Tunic,
    Thanks for raising this. I can see that Image Styles Generator was created in June 2023 - do you know if you had tests running on DrupalCI before the switch over to Gitlab Pipelines? I recall that DrupalCI had exactly this behaviour and I discussed it with one of the core committers responsible for the testing system. I will try to find that issue.

    The solution was that any "require": dependencies in the submodule should be repeated as "require-dev": dependencies in the main module. This does not impact the ability to install the main module when those dependencies are not available, but they will be loaded during the test set-up, which is exactly what you want.

  • 🇪🇸Spain tunic Madrid

    No, no module had o tests before, not in Drupal CI but also not in Gitlab CI.

    The require-dev seems like a reasonable way to solve this in a simple way without increasing complexity in the GitLab CI testing workflow, I'll try that, thanks!

  • 🇪🇸Spain fjgarlin

    I agree that the workaround is simple enough to not do anything in the templates. In any case, I am assigning credit as this is a very valid question and an equally good reply/workaround.

  • 🇪🇸Spain tunic Madrid

    For anyone coming to this issue with the same problem I confirm that requrie-dev trick solved the issue.

    Thanks!

Production build 0.71.5 2024