3

Running mode: developer I was getting blank frontend page. I checked system.log and debug.log in magento and found out there was some errors related to some broken reference.

main.INFO: Broken reference: the 'logger' element cannot be added as child to 'after.body.start', because the latter doesn't exist [] []
main.INFO: Broken reference: the 'theme.active.editor' element cannot be added as child to 'after.body.start', because the latter doesn't exist [] []

The frontend page was showing blank but it was actually loading some html. I check for solution and found an answer in this thread https://stackoverflow.com/questions/55928892/magento-2-blank-page-but-not-empty

This thread suggested to delete the global.php file located in generated/metadata, and following this solved my issue and front end of my website loaded properly.

But now whenever I run the command

php bin/magento setup:di:compile

the global.php file is generated again and my website's frontend shows blank page again and deleting global.php solves it. I got some information related to global.php file in this thread Purpose of magento\generated\metadata\global.php file and is it safe to delete this file?

According to above thread

"The code compiler creates generated/metadata/global.php, which is a PHP serialized map of all constructor definitions mixed with object linking configuration defined in di.xml. di.xml is the dependency injection configuration. There is a global app/etc/di.xml and there can one defined for every module ."

This also happens when I run my website in production mode, and deleting global.php solves it. Now my question is why magento is generating global.php file if it is neither using it in developer mode nor production mode as deleting this file does not give any error and the website works perfectly.

And also broken reference error in fresh install of magento, does it means that it is some bug related to magento and how can one debug this problem further. I am asking how to debug it because as we can see in the error there is no mention of any file just a reference 'after.body.start'.

Update: I am running it locally on my PC, and I am using xampp version-3.2.3 on windows operating system.

0

Goto Magento\Framework\View\Element\Template\File\Validator

Replace isPathInDirectories() function with bellow code

protected function isPathInDirectories($path, $directories)
{
    if (!is_array($directories)) {
        $directories = (array)$directories;
    }
    $realPath = $this->fileDriver->getRealPath($path);
    $realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
    foreach ($directories as $directory) {
        if (0 === strpos($realPath, $directory)) {
            return true;
        }
    }
    return false;
}

this will solve your problem

  • I have tried this method when I was getting blank admin page and yes this was the answer for that case. But here my question was related to global.php file and how to debug the issue "broken reference". – Rajeev Singh Jul 15 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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