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

1

6

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).

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

Uncaught SyntaxError: Invalid or unexpected token

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

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

enter image description here

Every red dot is the character \u0.

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

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

My 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.

Stage answered 10/6, 2016 at 7:58 Comment(0)
S
10

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

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

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;
}
Stage answered 10/6, 2016 at 9:18 Comment(2)
Still experiencing this even with sendfile off;Positron
Having same problem with locak IIS and IISExpress on Windows 10. Any ideas?Simile

© 2022 - 2024 — McMap. All rights reserved.