Yii2框架加载js文件return错误

Yii2 framework loaded js file return errors

我使用yii2 AppAsset组件注册js文件:

<?php

namespace backend\assets;

use yii\web\AssetBundle;

class DiyAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl  = '@web';
    public $css = [
        //'css/diy.css',
    ];
    public $js = [
        'js/base.js',
    ];
    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset',
    ];

}

js文件内容: the js file content

js文件加载成功,但是chrome浏览器显示错误:

大家可以帮帮我吗?

很可能你使用 VirtualBox 来 运行 Yii2 应用程序。

如果是 - 在您的 Apache 或 Nginx 配置中禁用 sendfile。看看这个 issue on GitHub

从上面的讨论我可以猜测你的 yii2 生成的资产文件可能有问题,我试过复制你的错误但没有成功,

我之前也遇到过这样的错误,当我复制粘贴以前的应用程序开始开发另一个应用程序时,我解决它的方法是删除生成的资产文件,因为当你 运行再次申请

如果您使用的是高级模板

要删除的资产位于根目录,目录结构如下

_protected
assets //delete the contents in here but dont delete the folder assets
backend
themes
uploads
 ....etc

希望对您有所帮助