Laravel + Vue上的随机JavaScript运行时错误

时间:2019-07-26 15:45:06

标签: php laravel apache docker vue.js

我正在使用Laravel 5.8 + Vue 2.5.17在apache 2.4和php 7.3上的docker上运行,我遇到了一个奇怪的问题,该问题极大地减慢了我的开发过程。 每次我重新加载添加我的自定义vue组件的laravel主页时,都有90%的机会出现随机javascript运行时错误,而其他10%的页面正确加载并且我的组件运行良好。

每次重新加载清除缓存(ctrl + f5)时,都会出现一些随机错误

  

SyntaxError:非法字符

     

SyntaxError:缺少参数列表后的

     

SyntaxError:期望的表达式,得到了'}'

     

SyntaxError:意外令牌:“]”

     

SyntaxError:“”字符串文字包含未转义的换行符

如果我从浏览器查看app.js源代码,看来当我收到错误消息时文件已损坏 enter image description here

或缺少一些代码 enter image description here

在没有磁盘的情况下查看app.js文件,我清楚地知道这是可以的,流至浏览器的文件有问题。 Tt可能是laravel缓存问题或与apache有关的问题,但我不知道在哪里看。

有猜到吗?

这是我的laravel .env文件

APP_NAME=Laravel
APP_ENV=local
APP_KEY=*****
APP_DEBUG=false
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=*****
DB_USERNAME=*****
DB_PASSWORD=*****

BROADCAST_DRIVER=log
CACHE_DRIVER=array
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

我的composer.json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "ichtrojan/laravel-location": "dev-master",
        "igaster/laravel_cities": "^1.3",
        "laravel/framework": "5.8.*",
        "laravel/tinker": "^1.0",
        "league/oauth2-client": "^2.4",
        "spatie/laravel-permission": "^2.37",
        "srmklive/paypal": "~1.0"
    },
    "require-dev": {
        "barryvdh/laravel-debugbar": "^3.2",
        "beyondcode/laravel-dump-server": "^1.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^3.0",
        "phpunit/phpunit": "^7.5"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

还有我的package.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.19",
        "bootstrap": "^4.1.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^4.0.7",
        "lodash": "^4.17.14",
        "popper.js": "^1.12",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.15.2",
        "sass-loader": "^7.1.0",
        "vue": "^2.5.17"
    },
    "dependencies": {
        "vue-moment": "^4.0.0",
        "vue-template-compiler": "^2.6.10"
    }
}

2 个答案:

答案 0 :(得分:0)

这种错误来自javascript端,我认为您的Vue配置不正确或缺少某些内容,或者没有以正确的方式调用此函数。通常,您最好在javascript代码端查看。希望会有所帮助。

答案 1 :(得分:0)

事实证明这是Apache的错误。

使用浏览器检查app.js,我确认每次文件内容由于损坏而有所不同,因此我将可能的问题缩小到与文件下载相关的问题。

首先,我尝试将Apache的版本从2.4降级到2.2,该错误已修复。

进一步调查,我查找了从apache下载的文件中可能存在的损坏错误,并发现MINMAXINFO。然后,我尝试在httpd.conf中启用选项EnableSendfile时保持apache 2.4,但是它没有用,然后我尝试禁用EnableMMAP,终于解决了该问题!