20

I have upgraded 2.2.6 version to 2.2.7 version but its showing below error in my website.

1 exception(s):
Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'C:/xampp2/htdocs/magento2/demo1/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: 'C:/xampp2/htdocs/magento2/demo1/vendor/magento/module-theme/view/frontend/templates/page/js/require_js.phtml' in module: '' block's name: 'require.js'
#0 C:\xampp2\htdocs\magento2\demo1\vendor\magento\framework\View\Element\Template.php(300): Magento\Framework\View\Element\Template->fetchView('C:/xampp2/htdoc...')
#1 C:\xampp2\htdocs\magento2\demo1\vendor\magento\framework\View\Element\AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml()
#2 C:\xampp2\htdocs\magento2\demo1\vendor\magento\framework\View\Result\Page.php(248): Magento\Framework\View\Element\AbstractBlock->toHtml()
#3 C:\xampp2\htdocs\magento2\demo1\vendor\magento\framework\View\Result\Layout.php(170): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#4 C:\xampp2\htdocs\magento2\demo1\vendor\magento\framework\Interception\Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#5 C:\xampp2\htdocs\magento2\demo1\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
#6 C:\xampp2\htdocs\magento2\demo1\vendor\magento\framework\Interception\Interceptor.php(153): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#7 C:\xampp2\htdocs\magento2\demo1\generated\code\Magento\Framework\View\Result\Page\Interceptor.php(130): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#8 C:\xampp2\htdocs\magento2\demo1\vendor\magento\framework\App\Http.php(139): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#9 C:\xampp2\htdocs\magento2\demo1\generated\code\Magento\Framework\App\Http\Interceptor.php(24): Magento\Framework\App\Http->launch()
#10 C:\xampp2\htdocs\magento2\demo1\vendor\magento\framework\App\Bootstrap.php(257): Magento\Framework\App\Http\Interceptor->launch()
#11 C:\xampp2\htdocs\magento2\demo1\index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#12 {main}

Same issue i am facing if i upgrade website from 2.6 to 2.3.

Is there any solution?

Sanjay Jethva
  • 1,399
  • 4
  • 18
  • 40

6 Answers6

41

if your magento installation is running on windows than in magento's some versions like in 2.2.7 we have to replace the code of file vendor/magento/framework/view/element/template/file/validator.php with this.

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;
}

and now reload the magento application.

Evgeny Levinsky
  • 1,187
  • 1
  • 7
  • 12
Naveen Jain
  • 530
  • 3
  • 7
14

This should be only a problem of your local installation, because your Magento instance is running on Windows.

So this could be a temporary fix in vendor\magento\framework\View\Element\Template\File\Validator.php

Go to line number 114 and change the line number and replace below line

$filename = str_replace('\\', '/', $filename);

with

$filename = str_replace('\\', '/', $this->fileDriver->getRealPath($filename));
Sanjay Jethva
  • 1,399
  • 4
  • 18
  • 40
torhoehn
  • 355
  • 4
  • 15
1

I had this problem in my case it was a module that I used in the registration.php file

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_Module',
    isset($file) ? dirname($file) : __DIR__
);

the problem is in this line "isset ($ file)? dirname ($ file): __DIR__" so I changed it to "__DIR__", and now it works, I hope it helps.

  • Had the same issue with a module of a colleague. Wasted so much time to find the reason for the problem. I'm glad to found your answer. Probably he introduced this by this hackish solution. – robsch Aug 03 '20 at 15:18
1

I got the same error on linux. If you are running Magento in developer mode, this may happen because Magento does not understand symlinks. To allow symlinks, simply execute the following sql:

update `core_config_data` set `value`='1' where `path`='dev/template/allow_symlink';

Then run: bin/magento cache:flush

HoaiNP
  • 21
  • 1
  • This was super helpful and worked for me after importing a production-mode database into a developer-mode environment. Thank you! – Mike Dubs Apr 12 '21 at 20:19
0

For Upgrade Magento 2.2.6 to Magento 2.3.0 without any issue, I have just upgrade one of our ongoing projects from Magento 2.2.6 to 2.3.0 and nothing break the functionality of the ongoing project.

you can easily upgrade using Magento command line,

You need to follow four steps to upgrade from older version to latest version Magento 2.3

For upgrade to Magento 2.3 You must require PHP 7.1.3+ or PHP 7.2.

You can't simply upgrade using Composer update command only.

Hope you will be helpful above steps.

Rakesh Jesadiya
  • 42,221
  • 18
  • 132
  • 183
  • Hello @Rakesh, i am using php version 7.1.7 and applied Mr. tho solution and website is not showing any error. my store is in development mode. but showing blank page. – Sanjay Jethva Dec 04 '18 at 06:17
0

I know it's quite old problem and everyone already knows the solution, but I created quick composer-based package with fix, just run in your Magento root:

composer require idealcode/magento2-windows-compatibility

I hope it will be useful.

Evgeny Levinsky
  • 1,187
  • 1
  • 7
  • 12