VPS business hosting starting at $29.95/24/7 premium technical support

How to fix Invalid template file error in Magento2 after version upgrade?

This is a very common issue you will face if you using windows machine for development.

Usual error message is:

Invalid template file: '/vendor/magento/module-theme/view/frontend/templates/page/js/require_js.phtml' in module: '' block's name: 'require.js'

So whats the solution?

In case of windows, just replace this function isPathInDirectories in vendor/magento/framework/view/element/template/file/validator.php

protected function isPathInDirectories($path, $directories)
    $realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
    if (!is_array($directories)) {
        $directories = (array)$directories;

    foreach ($directories as $directory) {
        if (0 === strpos($realPath, $directory)) {
            return true;
    return false;



Author: Harshvardhan Malpani

PHP Developer based in New Delhi, India. Working as a freelance web developer providing server deployment, website development and maintenance services.

Leave a Reply

Your email address will not be published. Required fields are marked *