How can I require a custom module hosted elsewhere with its contrib dependencies being downloaded too? Hi I am trying to setup my new Drupal 8 site with composer, but I got few issues.
I tried to setup the site site by following the Guide from here and was able to setup the site successfully.
After that I tried to install a custom module which is hosted on Bitbucket and I am able to download the package using Composer, but the problem is the module has some other contributed module dependency but the dependency module is not downloaded along with the custom module.
I followed the guide from here and added composer.json file to my custom module along with the dependency, but after running composer require custom/custom_module only the custom module is installed but not the dependency.
My root directory composer.json file repositories section looks like this.
&quot;repositories&quot;: [
    {
        &quot;type&quot;: &quot;composer&quot;,
        &quot;url&quot;: &quot;https://packages.drupal.org/8&quot;
    },
    {
      &quot;type&quot;: &quot;package&quot;,
      &quot;package&quot;: {
        &quot;name&quot;: &quot;custom/custom_module&quot;,
        &quot;version&quot;: &quot;master&quot;,
        &quot;type&quot;: &quot;drupal-custom-module&quot;,
        &quot;source&quot;: {
          &quot;type&quot;: &quot;git&quot;,
          &quot;url&quot;: &quot;git@bitbucket.org:username/custom-module.git&quot;,
          &quot;reference&quot;: &quot;master&quot;
        }
      }
    }
],

The composer.json file from the custom module is the following.
{
    &quot;name&quot;: &quot;custom/custom_module&quot;,
    &quot;description&quot;: &quot;This is a Custom Module with Different functionalities.&quot;,
    &quot;type&quot;: &quot;drupal-custom-module&quot;,
    &quot;minimum-stability&quot;: &quot;dev&quot;,
    &quot;require&quot;: {
        &quot;drupal/restui&quot;: &quot;~1.16&quot;
    }
}

I also chaged the line &quot;drupal/restui&quot;: &quot;~1.16&quot; as &quot;drupal/restui&quot;: &quot;^1.16&quot; but with no success.
I even tried running composer update in the custom module directory as I was not sure whether dependencies will be installed along with custom module.
After running composer update in the custom module directory I got this error.

Your requirements could not be resolved to an installable set of packages.

Problem 1



The requested package drupal/restui could not be found in any version, there may be a typo in the package name.


Potential causes:


A typo in the package name
The package is not available in a stable-enough version according to your minimum-stability setting
see https://getcomposer.org/doc/04-schema.md#minimum-stability for more details.
It's a private package and you forgot to add a custom repository to find it


Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

On Drupal.org I can find the module with that version here.
EDIT 1
I have added below to the composer.json file from the custom module but still same issue.
&quot;repositories&quot;: [
  {
    &quot;type&quot;: &quot;composer&quot;,
    &quot;url&quot;: &quot;https://packages.drupal.org/8&quot;
  }
],

EDIT 2 : Seems recursive package download is not possible with composer. Refer Why can't Composer load repositories recursively? and Add support for installing libraries via asset-packagist
Just for this question I created a dummy module at https://github.com/leymannx/custom_module which has a composer.json similar to yours with drupal/restui in the &quot;require&quot; section and &quot;type&quot;: &quot;drupal-custom-module&quot;.
And then in a D8 project's composer.json I adjusted the &quot;repositories&quot; section to look like this:
&quot;repositories&quot;: [
    {
        &quot;type&quot;: &quot;composer&quot;,
        &quot;url&quot;: &quot;https://packages.drupal.org/8&quot;
    },
    {
        &quot;type&quot;: &quot;github&quot;,
        &quot;url&quot;:  &quot;https://github.com/leymannx/custom_module&quot;
    }
],

In the &quot;installer-paths&quot; section I added:
 &quot;web/modules/custom/{$name}&quot;: [&quot;type:drupal-custom-module&quot;]

I then simply ran composer require leymannx/custom_module and it downloaded the module and drupal/restui both to the right places. Of course you now can ignore the custom module with your repo's .gitignore file.
I guess the trick was to have the &quot;repositories&quot; section adjusted like above. And I guess you also can use proper versioning for the custom module when you tagged some releases. Right now it just downloads dev-main.