Magento2: Windows separator fix on Magento 2.3

Created on 30 Nov 2018  路  12Comments  路  Source: magento/magento2

Preconditions (*)

  1. Magento 2.3.0 (fresh installation from composer)
  2. Windows only

Steps to reproduce (*)

  1. Open any URL in frontend or backend

Expected result (*)

  1. The correct output

Actual result (*)

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'
#0 [..]\vendor\magento\framework\View\Element\Template.php(301): Magento\Framework\View\Element\Template->fetchView('C:/www/cardio_t...')
#1 [..]\vendor\magento\framework\View\Element\AbstractBlock.php(668): Magento\Framework\View\Element\Template->_toHtml()
#2 [..]\vendor\magento\framework\View\Result\Page.php(249): Magento\Framework\View\Element\AbstractBlock->toHtml()
#3 [..]\vendor\magento\framework\View\Result\Layout.php(171): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#4 [..]\vendor\magento\framework\Interception\Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#5 [..]\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
#6 [..]\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 [..]\generated\code\Magento\Framework\View\Result\Page\Interceptor.php(39): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#8 [..]\vendor\magento\framework\App\Http.php(139): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#9 [..]\vendor\magento\framework\App\Bootstrap.php(258): Magento\Framework\App\Http->launch()
#10 [..]\index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#11 {main}
  1. Magento\Framework\View\Element\Template\File\Validator function isPathInDirectories: Windows uses "\" as separator, the array "directories" contains entries with "/" as separator, so the check will always fail.
    $realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path)); could be a solution.
Format is valid

Most helpful comment

I've run Magento on Windows servers for years without any issues. The fix for me was replacing
$realPath = $this->fileDriver->getRealPath($path);
with
$realPath = str_replace('\', '/', $this->fileDriver->getRealPath($path));

All 12 comments

Hi @vincent-bosche. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me $VERSION instance

where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.

@vincent-bosche do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

HI @vincent-bosche

Magento 2.3.x technology stack requirements
Operating systems (Linux x86-64)
Linux distributions, such as RedHat Enterprise Linux (RHEL), CentOS, Ubuntu, Debian, and similar.

https://devdocs.magento.com/guides/v2.3/install-gde/system-requirements-tech.html

I've run Magento on Windows servers for years without any issues. The fix for me was replacing
$realPath = $this->fileDriver->getRealPath($path);
with
$realPath = str_replace('\', '/', $this->fileDriver->getRealPath($path));

Can reproduce, fresh install of magento 2.3 on development wamp server is totally borked.

PLEASE INSTALL NEW RELEASES ON WINDOWS AT LEAST ONCE =P

[2018-12-03 17:45:20] main.CRITICAL: Invalid template file: 'C:/wamp64/www/magento/vendor/magento/module-backend/view/adminhtml/templates/admin/login.phtml' in module: 'Magento_Backend' block's name: 'admin.login' [] []

gfguru thanks for the fix!
in: www\vendor\magento\framework\View\Element\Template\File\Validator.php

I've run Magento on Windows servers for years without any issues. The fix for me was replacing
$realPath = $this->fileDriver->getRealPath($path);
with
$realPath = str_replace('\', '/', $this->fileDriver->getRealPath($path));

@vincent-bosche Did you solve in windows platform?

For Windows, this is the workaround for now, modify this below file {Magento_Dir}\vendor\magento\framework\View\Element\Template\File\Validator.php

Comment the existing $realpath around line 138 and add the new $realPath

//$realPath = $this->fileDriver->getRealPath($path);
$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));

@saktib Still getting same error after update $realPath = str_replace('\', '/', $this->fileDriver->getRealPath($path));
Anything else shall i need to focus?

@Jeeva-Rathinam
From your comment I can see you are missing one backslash, it should be like below.
$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));

@saktib Still getting same error after update $realPath = str_replace('\', '/', $this->fileDriver->getRealPath($path));
Anything else shall i need to focus?
Try this $realPath = str_replace('\', '/', $this->fileDriver->getRealPath($path));

I think you're going down the wrong path installing with windows. Waste of time with M2.3. The routing and build system is bound to have other errors that will keep popping up.

I'm on Ubuntu 18 and I'm still getting this issue. The proposed fix did not fix the problem for me. Telling the customer to use a different operating system is not the kind of support that Magento would allow Extension developers to get away with.

A solution that did work for me was to specify a Theme for the website. Upon installation this seems to have been lost and the db was giving a blank string for the theme name.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andreaskoch picture andreaskoch  路  3Comments

kandrejevs picture kandrejevs  路  3Comments

BenSpace48 picture BenSpace48  路  3Comments

MauroNigrele picture MauroNigrele  路  3Comments

jzalenski picture jzalenski  路  3Comments