Solution for Invalid template file: ‘vendor/magento/module-theme/view/frontend/templates/page/js/require_js.phtml ” block’s name: ‘require.js’ in Magento 2.3.x

Error Message:
1 exception(s):
Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: ‘vendor/magento/module-theme/view/frontend/templates/page/js/require_js.phtml’ in module: ” block’s name: ‘require.js’

Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: ‘vendor/magento/module-theme/view/frontend/templates/page/js/require_js.phtml’ in module: ” block’s name: ‘require.js’
<pre>#1 Magento\Framework\View\Element\Template->_toHtml() called at [vendor\magento\framework\View\Element\AbstractBlock.php:668]
#2 Magento\Framework\View\Element\AbstractBlock->toHtml() called at [vendor\magento\framework\View\Result\Page.php:249]
#3 Magento\Framework\View\Result\Page->render(&Magento\Framework\App\Response\Http\Interceptor#00000000126210e20000000016f4226f#) called at [vendor\magento\framework\View\Result\Layout.php:171]
#4 Magento\Framework\View\Result\Layout->renderResult(&Magento\Framework\App\Response\Http\Interceptor#00000000126210e20000000016f4226f#) called at [vendor\magento\framework\Interception\Interceptor.php:58]
#5 Magento\Framework\View\Result\Page\Interceptor->___callParent(‘renderResult’, array(&Magento\Framework\App\Response\Http\Interceptor#00000000126210e20000000016f4226f#)) called at [vendor\magento\framework\Interception\Interceptor.php:138]
#6 Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(&Magento\Framework\App\Response\Http\Interceptor#00000000126210e20000000016f4226f#) called at [vendor\magento\framework\Interception\Interceptor.php:153]
#7 Magento\Framework\View\Result\Page\Interceptor->___callPlugins(‘renderResult’, array(&Magento\Framework\App\Response\Http\Interceptor#00000000126210e20000000016f4226f#), array(array(‘result-messages’, ‘result-builtin-c…’, ‘result-varnish-c…’))) called at [generated\code\Magento\Framework\View\Result\Page\Interceptor.php:130]
#8 Magento\Framework\View\Result\Page\Interceptor->renderResult(&Magento\Framework\App\Response\Http\Interceptor#00000000126210e20000000016f4226f#) called at [vendor\magento\framework\App\Http.php:140]
#9 Magento\Framework\App\Http->launch() called at [generated\code\Magento\Framework\App\Http\Interceptor.php:24]
#10 Magento\Framework\App\Http\Interceptor->launch() called at [vendor\magento\framework\App\Bootstrap.php:258]
#11 Magento\Framework\App\Bootstrap->run(&Magento\Framework\App\Http\Interceptor#00000000126210e70000000016f4226f#) called at [index.php:39]
</pre>

Go to Following Method :

File Path:
vendor\magento\framework\View\Element\Template\File\Validator.php

Method: protected function isPathInDirectories($path, $directories)
Add following change,
protected function isPathInDirectories($path, $directories)
{
if (!is_array($directories)) {
$directories = (array)$directories;
}
$realPath = $this->fileDriver->getRealPath($path);
$realPath = str_replace(‘\\’, ‘/’, $realPath); // add new this line in your file.
foreach ($directories as $directory) {
if (0 === strpos($realPath, $directory)) {
return true;
}
}
return false;
}

Save Tree !!! Save Water !!!