Yii2 framework loaded js file return errors

127 Views Asked by At

I using yii2 AppAsset component registered js file:

<?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',
    ];

}

the js file content: the js file content

the js file loaded success,but chrome broswer show me the error:

show erros

expland erros

can everyboy help me?

2

There are 2 best solutions below

1
On BEST ANSWER

Most probably you use VirtualBox to run Yii2 application.

If yes - disable sendfile in your Apache or Nginx config. Check out this issue on GitHub

0
On

From the above discussion i can guess that there might be a problem with your yii2 generated asset files, ive tried duplicating your error but without success,

I had also got such an error before when i copy pasted a previous app to start developing another app from that, The way i solved it was to delete the generated assets files as yii2 will recreate the files when you run the application again

If you are using the advanced template

The assets to delete are located at the root directory that is the directory structure looks like

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

I hope this helps