Skip to content

Magento 2.4.6: Getting error “Namespace not defined properly” when compile command running

When I am trying to compile, then I am getting Below error:

Namespace not defined properly

you can see proper command running here :

www-data@robert-php-fpm:/var/www/html$ bin/magento setup:di:compile -v
Compilation was started.
Repositories code generation... 1/9 [===>------------------------]  11% &lt 1 sec 109.0 MiB
In FileClassScanner.php line 201:
                                                              
  [MagentoSetupModuleDiCodeReaderInvalidFileException]  
  Namespace not defined properly                              
                                                              

Exception trace:
  at /var/www/html/setup/src/Magento/Setup/Module/Di/Code/Reader/FileClassScanner.php:201
 MagentoSetupModuleDiCodeReaderFileClassScanner->isBracedNamespace() at /var/www/html/setup/src/Magento/Setup/Module/Di/Code/Reader/FileClassScanner.php:151
 MagentoSetupModuleDiCodeReaderFileClassScanner->extract() at /var/www/html/setup/src/Magento/Setup/Module/Di/Code/Reader/FileClassScanner.php:89
 MagentoSetupModuleDiCodeReaderFileClassScanner->getClassName() at /var/www/html/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php:115
 MagentoSetupModuleDiCodeReaderClassesScanner->extract() at /var/www/html/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php:87
 MagentoSetupModuleDiCodeReaderClassesScanner->getList() at /var/www/html/setup/src/Magento/Setup/Module/Di/App/Task/Operation/RepositoryGenerator.php:61
 MagentoSetupModuleDiAppTaskOperationRepositoryGenerator->doOperation() at /var/www/html/setup/src/Magento/Setup/Module/Di/App/Task/Manager.php:56
 MagentoSetupModuleDiAppTaskManager->process() at /var/www/html/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php:216
 MagentoSetupConsoleCommandDiCompileCommand->execute() at /var/www/html/vendor/symfony/console/Command/Command.php:298
 SymfonyComponentConsoleCommandCommand->run() at /var/www/html/vendor/symfony/console/Application.php:1040
 SymfonyComponentConsoleApplication->doRunCommand() at /var/www/html/vendor/symfony/console/Application.php:301
 SymfonyComponentConsoleApplication->doRun() at /var/www/html/vendor/magento/framework/Console/Cli.php:116
 MagentoFrameworkConsoleCli->doRun() at /var/www/html/vendor/symfony/console/Application.php:171
 SymfonyComponentConsoleApplication->run() at /var/www/html/bin/magento:23

setup:di:compile

www-data@robert-php-fpm:/var/www/html$