'Uncaught Error: Class "Symfony\Bundle\DebugBundle\DebugBundle" not found

I trying to deploy my application (Symfony 6 and php 8) through the Gandi.net french service. When I run the command to deploy the app by ssh I get the following error message in my terminal :

Executing script cache:clear [KO]

[KO]

Script cache:clear returned with error code 255

!! Symfony\Component\ErrorHandler\Error\ClassNotFoundError {#75

!! #message: """

!! Attempted to load class "DebugBundle" from namespace "Symfony\Bundle\DebugBundle".\n

!! Did you forget a "use" statement for another namespace?

!! """

!! #code: 0

!! #file: "./vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php"

!! #line: 131

!! trace: {

!! ./vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php:131 { …}

!! ./vendor/symfony/http-kernel/Kernel.php:382 { …}

!! ./vendor/symfony/http-kernel/Kernel.php:768 { …}

!! ./vendor/symfony/http-kernel/Kernel.php:128 { …}

!! ./vendor/symfony/framework-bundle/Console/Application.php:166 { …}

!! ./vendor/symfony/framework-bundle/Console/Application.php:72 { …}

!! ./vendor/symfony/console/Application.php:171 { …}

!! ./vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:54 { …}

!! ./vendor/autoload_runtime.php:29 { …}

!! ./bin/console:11 {

!! ›

!! › require_once dirname(DIR).'/vendor/autoload_runtime.php';

!! ›

!! arguments: {

!! "/tmp/build.14jKbmPhHD/vendor/autoload_runtime.php"

!! }

!! }

!! }

!! }

!! 2022-03-11T15:10:40+00:00 [critical] Uncaught Error: Class "Symfony\Bundle\DebugBundle\DebugBundle" not found

!!

Script @auto-scripts was called via post-install-cmd

-----> Building new application failed

-----> Aborting deployment

This is the 2 files where the DebugBundle is mentioned.

  • Composer.lock

    "autoload": { "psr-4": {
    "Symfony\Bundle\DebugBundle\": ""
    },
    "exclude-from-classmap": [ "/Tests/"

    ]
    },

  • Bundles.php

    ['all' => true], Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true], Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], ];

The error suppose that I forgot a “use” but I never instantiate the DebugBundle so I never had to write a use for him. I try to run composer require symfony/debug-bundle and do a composer update but nothing change.
I already try to change de content of the composer.lock by changing :
"autoload": {
                "psr-4": {  
                    "Symfony\\Bundle\\DebugBundle\\": ""   
                }, 
                "exclude-from-classmap": [  
                    "/Tests/" 
                ]  
            },

To

"autoload": {  
                "psr-4": {  
                    "Symfony\\Bundle\\DebugBundle\\": “App\src”   
                },
                "exclude-from-classmap": [  
                    "/Tests/"   
                ] 
            }, 

but when the composer install or update is run the “App/src” is delete and the file return to is original value. I’m running out of idea so I hope your guys can help me.


Have a nice day.


Aimerick

terminal

Bundles.php

composer.lock



Solution 1:[1]

I'm getting the same error, what I think is happening is that the composer command is installing the "prod" requirements, meaning it will correctly skip those bundles mentioned in "require-dev" as those are development only.

However, there must be some code in the runtime that isn't checking on which env it's running on or a misconfiguration that still tries to load all bundles when the Kernel is loading, (or it's not aware of the APP_ENV=prod), and therefor still tries to load the debug bundle (and other dev bundles), even though these were not installed by composer.

You'll notice these are the bundles that have dev => true in bundles.php. You'll notice that by removing these one by one, the error will shift to the next one that has dev => true.

I have made sure my env vars are set before any composer command is run, so it can't be that.

When SHH'ed into my server, I can go into the "bin" directory of my project and run "php console about" there. It seems to think it's a dev env, even though its deployment script ought to have set the APP_ENV var.

#php console about


Symfony


Version 6.0.8
Long-Term Support No
End of maintenance 01/2023 (in +269 days)
End of life 01/2023 (in +269 days)


Kernel


Type App\Kernel
Environment dev
Debug true
Charset UTF-8
Cache directory ./var/cache/dev (1.7 MiB)
Build directory ./var/cache/dev (1.7 MiB)
Log directory ./var/log (0 B)


PHP


Version 8.1.5
Architecture 64 bits
Intl locale en_US_POSIX
Timezone Europe/Brussels (2022-05-07T16:18:34+02:00)
OPcache true
APCu true
Xdebug false


So what I assume is that the "export APP_ENV=prod" and "export APP_DEBUG=0" are not remembered by the system.

Therefor, I ran "composer dump-env prod" manually on the system, and that generates a .env.local.php containing the APP_ENV and APP_DEBUG lines, and now these are respected and the site seems to load (onwards to fixing my data).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1