laravel 未捕获的语法错误:Browserify 编译的文件中的无效或意外标记

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37742950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:58:48  来源:igfitidea点击:

Uncaught SyntaxError: Invalid or unexpected token in file compiled by Browserify

laravelbrowserifylaravel-elixir

提问by siannone

My project is based on Laravel and makes use of Laravel Elixir in order to compile and minify the client side code (which is written in ECMAScript 6).

我的项目基于 Laravel,并使用 Laravel Elixir 来编译和缩小客户端代码(用 ECMAScript 6 编写)。

I noticed that if I make any change to the client side code, then compile everything again using gulpand reload the page I get the following error in Chrome:

我注意到,如果我对客户端代码进行任何更改,然后使用再次编译所有内容gulp并重新加载页面,我会在 Chrome 中收到以下错误:

Uncaught SyntaxError: Invalid or unexpected token

Failed to parse SourceMap: http://192.168.99.100/js/app.js.map

未捕获的语法错误:无效或意外的令牌

解析 SourceMap 失败:http: //192.168.99.100/js/app.js.map

If I inspect the app.jsI can see why I'm having that problem:

如果我检查app.js我可以看到为什么我遇到这个问题:

enter image description here

在此处输入图片说明

Every red dot is the character \u0.

每个红点都是字符\u0

After that I inspected the same file in my IDE and there are no such characters at the end of it.

之后,我在 IDE 中检查了同一个文件,在它的末尾没有这样的字符。

If I revert my changes back and then recompile again with gulpeverything starts working again.

如果我恢复我的更改,然后再次重新编译,gulp一切都会重新开始工作。

My gulpfile.js:

我的gulpfile.js

var elixir = require('laravel-elixir');
require('laravel-elixir-vueify');

// Enable full sourcemaps with browserify. Disable in production.
elixir.config.js.browserify.options.debug = true;

// Disable notifications
process.env.DISABLE_NOTIFIER = true;

elixir(function(mix)
{
    // Compile SASS
    mix.sass('app.scss');

    mix.browserify('app.js');

    mix.browserSync({
        notify : false,
        open: false,        
        proxy : '192.168.99.100',
        reloadDelay: 2000
    });
});

Not sure if it matters but the app is running in multiple docker containers inside a shared folder, hosted by Mac OS X.

不确定这是否重要,但该应用程序在共享文件夹内的多个 docker 容器中运行,由 Mac OS X 托管。

回答by siannone

Turns out that the problem was caused by an Nginx misconfiguration. I got a really useful hint by looking at this discussion.

原来问题是由 Nginx 错误配置引起的。通过查看这个讨论,我得到了一个非常有用的提示。

I needed to disable the use of sendfile in Nginx by changing the default.confin my case:

在我的情况下,我需要通过更改default.conf来禁用在 Nginx 中使用 sendfile :

location / {

    # Try to serve the request as a file first, but if it cannot be found
    # try to serve the default index file for a directory that matches the
    # request.
    try_files $uri $uri/ /index.php?$query_string;
    index     index.php index.html index.htm;
    sendfile  off;
}