How to fix the «Invalid template file» / «require_js.phtml» failure for 2.3 ≤ Magento < 2.4.5 in Windows?

Replace the code:

with the following one:

$isWin = 'WIN' === strtoupper(substr(PHP_OS, 0, 3)); /** @var bool $isWin */
foreach ($directories as $directory) {
	if (0 === strpos($realPath, !$isWin ? $directory : str_replace('/', DIRECTORY_SEPARATOR, $directory))) {

For other Magento versions:

  1. For Magento ≥ 2.4.5
  2. For Magento 2.2.x

See also:

hi tried it but still no success any other solution ?

and i am using magento 2.3

It always work for me. Re-check your code.

for magento 2.2.9

$isWin = 'WIN' === strtoupper(substr(PHP_OS, 0, 3)); /** @var bool $isWin */
        foreach ($directories as $directory) {
            if (0 === strpos($this->fileDriver->getRealPath($path),
                    !$isWin ? $directory : $this->fileDriver->getRealPath($directory))
            ) {
                return true;
            }
        }
1 Like

Yes, I have already published the solution for Magento 2.2.x here: How to fix the «Invalid template file» / «require_js.phtml» failure of Magento 2.2.x in Windows?

1 Like

The same fix works for Magento 2.4.0.

1 Like

See also: windows-filesystem tagged topics.

How to fix the «Invalid template file» / «require_js.phtml» failure for Magento ≥ 2.4.5 in Windows?

How do I install Magento 2.4 to Windows?