I am using Magento 2.4.5 and php 8.1

when I try to sudo php bin/magento setup:di:compile

I get this error:

Compilation was started.
Repositories code generation... 1/9 [===>------------------------]  11% 1 sec 119.0 MiBUnclosed '{' on line 23#0 /var/www/magento2/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile()
#1 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#2 /var/www/magento2/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php(134): class_exists()
#3 /var/www/magento2/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php(117): Magento\Setup\Module\Di\Code\Reader\ClassesScanner->includeClass()
#4 /var/www/magento2/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php(87): Magento\Setup\Module\Di\Code\Reader\ClassesScanner->extract()
#5 /var/www/magento2/setup/src/Magento/Setup/Module/Di/App/Task/Operation/RepositoryGenerator.php(61): Magento\Setup\Module\Di\Code\Reader\ClassesScanner->getList()
#6 /var/www/magento2/setup/src/Magento/Setup/Module/Di/App/Task/Manager.php(56): Magento\Setup\Module\Di\App\Task\Operation\RepositoryGenerator->doOperation()
#7 /var/www/magento2/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php(216): Magento\Setup\Module\Di\App\Task\Manager->process()
#8 /var/www/magento2/vendor/symfony/console/Command/Command.php(255): Magento\Setup\Console\Command\DiCompileCommand->execute()
#9 /var/www/magento2/vendor/symfony/console/Application.php(1009): Symfony\Component\Console\Command\Command->run()
#10 /var/www/magento2/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#11 /var/www/magento2/vendor/magento/framework/Console/Cli.php(116): Symfony\Component\Console\Application->doRun()
#12 /var/www/magento2/vendor/symfony/console/Application.php(149): Magento\Framework\Console\Cli->doRun()
#13 /var/www/magento2/bin/magento(23): Symfony\Component\Console\Application->run()
#14 {main}

I checked the debug log and system logs and nothing there. How do I debug this? thx

1 Answer 1


You can find in which class you have an issue using the below file path.


Add the below line in the getList() function.

echo "Class: ".$path."\n"

enter image description here

After adding please run php bin/magento setup:di:compile command. you can see the class path. once you found and fix it please remove that line.

  • Thanks Msquare: My last path is Class: /var/www/magento2/vendor/magento/module-catalog-search Unclosed '{' on line 23#0 /var/www/magento2/vendor/composer/ClassLoader.php(432): Composer\Autoload\ClassLoader::Composer\Autoload\{closure}(). Where Do I remove the path line?
    – Henri
    Jan 16, 2023 at 16:20
  • @Henri Once you got the class then undo your changes from the above mention file path and Removed echo from it. and check compilation again.
    – Msquare
    Jan 16, 2023 at 16:36
  • Hi Msquare. Thx for your help. My question is where do I know where to fix the class? It says there is an Unclosed '{' on line 23 but it does not tell me where I should fix the class.
    – Henri
    Jan 16, 2023 at 16:40
  • @Henri Can you connect with me on skype? join.skype.com/invite/nkVHQ28bB2M6
    – Msquare
    Jan 16, 2023 at 16:48
  • Many thanks Msquare I was able to find the right class in my vendor directory and correct the mistake.
    – Henri
    Jan 16, 2023 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.