title: Symfony 5: error loading bundle at extension's load method
body: <p>I am trying to understand the necessary steps for creating reusable bundles. I'm using Symfony 5.2 and PHP 8.0.</p>
  <p>I have two sibling directories containing the projects <code>MainProject</code> and <code>FirstModule</code>.</p>
  <p><code>composer.json</code> for project <code>MainProject</code>:</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;type&quot;: &quot;project&quot;,
      &quot;name&quot;: &quot;modulartest/main_project&quot;,
      &quot;license&quot;: &quot;unlicense&quot;,
      &quot;minimum-stability&quot;: &quot;dev&quot;,
      &quot;prefer-stable&quot;: true,
      &quot;repositories&quot;: [{
          &quot;type&quot;: &quot;path&quot;,
          &quot;url&quot;: &quot;../FirstModule/&quot;
      }],
      &quot;require&quot;: {
          &quot;php&quot;: &quot;&gt;=8.0&quot;,
          &quot;ext-ctype&quot;: &quot;*&quot;,
          &quot;ext-iconv&quot;: &quot;*&quot;,
          &quot;doctrine/annotations&quot;: &quot;^1.12&quot;,
          &quot;modulartest/first_module&quot;: &quot;dev-master&quot;,
          &quot;sensio/framework-extra-bundle&quot;: &quot;^6.1&quot;,
          &quot;symfony/console&quot;: &quot;5.2.*&quot;,
          &quot;symfony/dotenv&quot;: &quot;5.2.*&quot;,
          &quot;symfony/flex&quot;: &quot;^1.3.1&quot;,
          &quot;symfony/framework-bundle&quot;: &quot;5.2.*&quot;,
          &quot;symfony/maker-bundle&quot;: &quot;^1.29&quot;,
          &quot;symfony/yaml&quot;: &quot;5.2.*&quot;
      },
      &quot;config&quot;: {
          &quot;optimize-autoloader&quot;: true,
          &quot;preferred-install&quot;: {
              &quot;*&quot;: &quot;dist&quot;
          },
          &quot;sort-packages&quot;: true
      },
      &quot;autoload&quot;: {
          &quot;psr-4&quot;: {
              &quot;App\\&quot;: &quot;src/&quot;
          }
      },
      &quot;autoload-dev&quot;: {
          &quot;psr-4&quot;: {
              &quot;App\\Tests\\&quot;: &quot;tests/&quot;
          }
      },
      &quot;replace&quot;: {
          &quot;symfony/polyfill-ctype&quot;: &quot;*&quot;,
          &quot;symfony/polyfill-iconv&quot;: &quot;*&quot;,
          &quot;symfony/polyfill-php72&quot;: &quot;*&quot;
      },
      &quot;scripts&quot;: {
          &quot;auto-scripts&quot;: {
              &quot;cache:clear&quot;: &quot;symfony-cmd&quot;,
              &quot;assets:install %PUBLIC_DIR%&quot;: &quot;symfony-cmd&quot;
          },
          &quot;post-install-cmd&quot;: [
              &quot;@auto-scripts&quot;
          ],
          &quot;post-update-cmd&quot;: [
              &quot;@auto-scripts&quot;
          ]
      },
      &quot;conflict&quot;: {
          &quot;symfony/symfony&quot;: &quot;*&quot;
      },
      &quot;extra&quot;: {
          &quot;symfony&quot;: {
              &quot;allow-contrib&quot;: false,
              &quot;require&quot;: &quot;5.2.*&quot;
          }
      }
  }
  </code></pre>
  <p><code>composer.json</code> for project <code>FirstModule</code>:</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;type&quot;: &quot;symfony-bundle&quot;,
      &quot;name&quot;: &quot;modulartest/first_module&quot;,
      &quot;license&quot;: &quot;unlicense&quot;,
      &quot;minimum-stability&quot;: &quot;dev&quot;,
      &quot;prefer-stable&quot;: true,
      &quot;require&quot;: {
          &quot;php&quot;: &quot;&gt;=8.0&quot;,
          &quot;ext-ctype&quot;: &quot;*&quot;,
          &quot;ext-iconv&quot;: &quot;*&quot;,
          &quot;sensio/framework-extra-bundle&quot;: &quot;^6.1&quot;,
          &quot;symfony/console&quot;: &quot;5.2.*&quot;,
          &quot;symfony/dotenv&quot;: &quot;5.2.*&quot;,
          &quot;symfony/flex&quot;: &quot;^1.3.1&quot;,
          &quot;symfony/framework-bundle&quot;: &quot;5.2.*&quot;,
          &quot;symfony/maker-bundle&quot;: &quot;^1.29&quot;,
          &quot;symfony/yaml&quot;: &quot;5.2.*&quot;
      },
      &quot;config&quot;: {
          &quot;optimize-autoloader&quot;: true,
          &quot;preferred-install&quot;: {
              &quot;*&quot;: &quot;dist&quot;
          },
          &quot;sort-packages&quot;: true
      },
      &quot;autoload&quot;: {
          &quot;psr-4&quot;: {
              &quot;ModularTest\\FirstModuleBundle\\&quot;: &quot;src/&quot;
          }
      },
      &quot;autoload-dev&quot;: {
          &quot;psr-4&quot;: {
              &quot;ModularTest\\FirstModuleBundle\\Tests\\&quot;: &quot;tests/&quot;
          }
      },
      &quot;conflict&quot;: {
          &quot;symfony/symfony&quot;: &quot;*&quot;
      },
      &quot;extra&quot;: {
          &quot;symfony&quot;: {
              &quot;allow-contrib&quot;: false,
              &quot;require&quot;: &quot;5.2.*&quot;
          }
      }
  }
  </code></pre>
  <p>In projeto <code>FirstModule</code>, I implemented a service, and a controller that uses that serve, all too simple, just for testing.</p>
  <p>Service code in <code>FirstModule\src\Controller\FirstController.php</code>:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  
  namespace ModularTest\FirstModuleBundle\Service;
  
  
  /**
   * Class FirstService
   * @package ModularTest\FirstModuleBundle\Service
   */
  class FirstService
  {
      /**
       * @return string
       */
      public function now(): string
      {
          return 'First Service time: '.date('c');
      }
  }
  </code></pre>
  <p>Code for controller in <code>FirstModule\src\Controller\FirstController.php</code>:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace ModularTest\FirstModuleBundle\Controller;
  
  use ModularTest\FirstModuleBundle\Service\FirstService;
  use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  use Symfony\Component\HttpFoundation\Response;
  use Symfony\Component\Routing\Annotation\Route;
  
  /**
   * Class FirstController
   * @package ModularTest\FirstModuleBundle\Controller
   */
  class FirstController extends AbstractController
  {
  
  
      /**
       * FirstController constructor.
       * @param FirstService $firstService
       */
      public function __construct(private FirstService $firstService)
      {
      }
  
      /**
       * @return Response
       */
      #[Route('/first', name: 'modular_test_first_module_first')]
      public function index(): Response
      {
          return $this-&gt;json([
              'message' =&gt; 'Welcome to your new controller!',
              'path' =&gt; 'src/Controller/FirstController.php',
              'date' =&gt; $this-&gt;firstService-&gt;now()
          ]);
      }
  }
  </code></pre>
  <p>I tried to follow rigorously the instructions given by Symfony documentation in those three pages:</p>
  <ul>
  <li><a href="https://symfony.com/doc/current/bundles.html" rel="nofollow noreferrer">https://symfony.com/doc/current/bundles.html</a></li>
  <li><a href="https://symfony.com/doc/current/bundles/best_practices.html" rel="nofollow noreferrer">https://symfony.com/doc/current/bundles/best_practices.html</a></li>
  <li><a href="https://symfony.com/doc/current/bundles/extension.html" rel="nofollow noreferrer">https://symfony.com/doc/current/bundles/extension.html</a></li>
  </ul>
  <p>Thus, I implemented bundle's class this way:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  
  namespace ModularTest\FirstModuleBundle;
  
  
  use Symfony\Component\HttpKernel\Bundle\Bundle;
  
  /**
   * Class ModularTestFirstModuleBundle
   * @package ModularTest\FirstModuleBundle
   */
  class ModularTestFirstModuleBundle extends Bundle
  {
      /**
       * @return string
       */
      public function getPath(): string
      {
          return \dirname(__DIR__);
      }
  }
  </code></pre>
  <p>I implemented extension's class this way:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  
  namespace ModularTest\FirstModuleBundle\DependencyInjection;
  
  
  use Symfony\Component\Config\FileLocator;
  use Symfony\Component\DependencyInjection\ContainerBuilder;
  use Symfony\Component\DependencyInjection\Extension\Extension;
  use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  
  /**
   * Class ModularTestFirstModuleExtension
   * @package ModularTest\FirstModuleBundle\DependencyInjection
   */
  class ModularTestFirstModuleExtension extends Extension
  {
  
      /**
       * @param array $configs
       * @param ContainerBuilder $container
       * @throws \Exception
       */
      public function load(array $configs, ContainerBuilder $container)
      {
          $loader = new YamlFileLoader(
              $container,
              new FileLocator(__DIR__.'/../Resources/config')
          );
          $loader-&gt;load('services.yaml');
      }
  }
  </code></pre>
  <p>And the content inside file <code>FirstModule\src\Resources\config\services.yaml</code> is as follows:</p>
  <pre class="lang-yaml prettyprint-override"><code># This file is the entry point to configure your own services.
  # Files in the packages/ subdirectory configure your dependencies.
  
  # Put parameters here that don't need to change on each machine where the app is deployed
  # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
  parameters:
  
  services:
      # default configuration for services in *this* file
      _defaults:
          autowire: true      # Automatically injects dependencies in your services.
          autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
  
      # makes classes in src/ available to be used as services
      # this creates a service per class whose id is the fully-qualified class name
      ModularTest\FirstModuleBundle\:
          resource: '../src/'
          exclude:
              - '../src/DependencyInjection/'
              - '../src/Entity/'
              - '../src/Kernel.php'
              - '../src/Tests/'
  
      # controllers are imported separately to make sure services can be injected
      # as action arguments even if you don't extend any base controller class
      ModularTest\FirstModuleBundle\Controller\:
          resource: '../src/Controller/'
          tags: ['controller.service_arguments']
  
      # add more service definitions when explicit configuration is needed
      # please note that last definitions always *replace* previous ones
  </code></pre>
  <p>Ok, all that done, I ran the server in <code>MainProject</code> with <code>symfony server:start</code>, e there were no immediate errors. Then I tried to browser the route that points to the controller that was defined by the bundle, that is, <code>https://127.0.0.1:8000/first</code>, and I received this:</p>
  <blockquote>
  <p>FileLocatorFileNotFoundException</p>
  <h3>The file &quot;../src/&quot; does not exist (in: &quot;C:\Users\eu\dev\php\symfony\modulartest\FirstModule\src\DependencyInjection/../Resources/config&quot;).</h3>
  </blockquote>
  <p>This is the Stack Trace:</p>
  <pre><code>Symfony\Component\Config\Exception\FileLocatorFileNotFoundException:
  The file &quot;../src/&quot; does not exist (in: &quot;C:\Users\eu\dev\php\symfony\modulartest\FirstModule\src\DependencyInjection/../Resources/config&quot;).
  
    at C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\config\FileLocator.php:71
    at Symfony\Component\Config\FileLocator-&gt;locate('../src/', 'C:\\Users\\eu\\dev\\php\\symfony\\modulartest\\FirstModule\\src\\DependencyInjection/../Resources/config', true)
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\config\Loader\FileLoader.php:117)
    at Symfony\Component\Config\Loader\FileLoader-&gt;glob('', true, array(object(FileExistenceResource)), false, false, array())
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\dependency-injection\Loader\FileLoader.php:176)
    at Symfony\Component\DependencyInjection\Loader\FileLoader-&gt;findClasses('ModularTest\\FirstModuleBundle\\', '../src/', array('../src/DependencyInjection/', '../src/Entity/', '../src/Kernel.php', '../src/Tests/'))
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\dependency-injection\Loader\FileLoader.php:99)
    at Symfony\Component\DependencyInjection\Loader\FileLoader-&gt;registerClasses(object(Definition), 'ModularTest\\FirstModuleBundle\\', '../src/', array('../src/DependencyInjection/', '../src/Entity/', '../src/Kernel.php', '../src/Tests/'))
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\dependency-injection\Loader\YamlFileLoader.php:671)
    at Symfony\Component\DependencyInjection\Loader\YamlFileLoader-&gt;parseDefinition('ModularTest\\FirstModuleBundle\\', array('resource' =&gt; '../src/', 'exclude' =&gt; array('../src/DependencyInjection/', '../src/Entity/', '../src/Kernel.php', '../src/Tests/')), 'C:\\Users\\eu\\dev\\php\\symfony\\modulartest\\FirstModule\\src\\DependencyInjection/../Resources/config\\services.yaml', array('autowire' =&gt; true, 'autoconfigure' =&gt; true))
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\dependency-injection\Loader\YamlFileLoader.php:234)
    at Symfony\Component\DependencyInjection\Loader\YamlFileLoader-&gt;parseDefinitions(array('parameters' =&gt; null, 'services' =&gt; array('ModularTest\FirstModuleBundle\' =&gt; array('resource' =&gt; '../src/', 'exclude' =&gt; array('../src/DependencyInjection/', '../src/Entity/', '../src/Kernel.php', '../src/Tests/')), 'ModularTest\FirstModuleBundle\Controller\' =&gt; array('resource' =&gt; '../src/Controller/', 'tags' =&gt; array('controller.service_arguments')))), 'C:\\Users\\eu\\dev\\php\\symfony\\modulartest\\FirstModule\\src\\DependencyInjection/../Resources/config\\services.yaml')
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\dependency-injection\Loader\YamlFileLoader.php:154)
    at Symfony\Component\DependencyInjection\Loader\YamlFileLoader-&gt;load('services.yaml')
       (C:\Users\eu\dev\php\symfony\modulartest\FirstModule\src\DependencyInjection\ModularTestFirstModuleExtension.php:30)
    at ModularTest\FirstModuleBundle\DependencyInjection\ModularTestFirstModuleExtension-&gt;load(array(array()), object(MergeExtensionConfigurationContainerBuilder))
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\dependency-injection\Compiler\MergeExtensionConfigurationPass.php:76)
    at Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass-&gt;process(object(ContainerBuilder))
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\http-kernel\DependencyInjection\MergeExtensionConfigurationPass.php:39)
    at Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass-&gt;process(object(ContainerBuilder))
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\dependency-injection\Compiler\Compiler.php:91)
    at Symfony\Component\DependencyInjection\Compiler\Compiler-&gt;compile(object(ContainerBuilder))
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\dependency-injection\ContainerBuilder.php:736)
    at Symfony\Component\DependencyInjection\ContainerBuilder-&gt;compile()
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\http-kernel\Kernel.php:541)
    at Symfony\Component\HttpKernel\Kernel-&gt;initializeContainer()
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\http-kernel\Kernel.php:780)
    at Symfony\Component\HttpKernel\Kernel-&gt;preBoot()
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\vendor\symfony\http-kernel\Kernel.php:183)
    at Symfony\Component\HttpKernel\Kernel-&gt;handle(object(Request))
       (C:\Users\eu\dev\php\symfony\modulartest\MainProject\public\index.php:20) 
  </code></pre>
  <p>What can I try next?</p>