15

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?

17

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.

  • 1
    Worked perfectly. Thanks alot. +1 – Shoaib Munir Apr 8 at 16:41
  • 1
    thanks alot, you save my day. +1 – Zeeshan Khuwaja Apr 25 at 4:05
12

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));
  • Hello @tho, i have applied this solution and now website is loading but home page and admin login shows blank page. – Sanjay Jethva Dec 4 '18 at 3:54
  • 1
    Thanks mate. worked for me. +1 – Shoaib Munir Apr 8 at 16:42
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.

  • 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 4 '18 at 6:17
0

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.

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.

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.