win10系统安装Magento 2报错解决方案

1892人浏览 2020-09-14

由于magento2对windows的兼容性并不好,win10系统在安装Magento2完成页面空白,F2查看js查看报错,或者报如下错误:

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

打开var/log/system.log查看错误日志如下:

解决方案:

项目根目录找到文件:vendor/magento/framework/View/Element/Template/File/Validator.php

在139行的位置找到:

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

替换为:

foreach ($directories as $directory) {
    $realDirectory = $this->fileDriver->getRealPath($directory);
  
    if (0 === strpos($realPath, $realDirectory)) {
        return true;
    }
}

重新编译一遍

php bin/magento setup:static-content:deploy -f

完成!

推荐文章

Mac下为php7.3编译安装Redis扩展(phpredis)教程(使用brew安装的php)
2020-09-25
PHP7.4 报错:Deprecated Functionality: implode(): Passing glue string after array is deprecated.
2020-09-18
使用富文本编辑器CKEditor 4 加Thinkphp6实现粘贴截图上传图片功能。
2020-09-10
搜索文章