BrowserSync / browser-sync

Keep multiple browsers & devices in sync when building websites. https://browsersync.io
https://discord.gg/2d2xUThp
Apache License 2.0
12.16k stars 754 forks source link

Local Tunnel error: Cannot read property 'sockets' of undefined #852

Closed giordanovi closed 8 years ago

giordanovi commented 8 years ago

Hi, when i run browser sync (2.9.8) with "tunnel" option enable, i give the following error:

node_modules/browser-sync/lib/browser-sync.js:668
                bs.io.sockets.emit("browser:reload");
                     ^

TypeError: Cannot read property 'sockets' of undefined
    at null._onTimeout (/Users/gio/Dropbox (Haus Media Design)/Haus/Roberta Krasnig/web/sources/node_modules/browser-sync/lib/browser-sync.js:668:22)
    at Timer.listOnTimeout (timers.js:89:15)

I run with the following code:

var browsers = BrowserSync.init({
        open           : false,
        logConnections : true,
        proxy          : '127.0.0.1:8100',
        online         : true,
        tunnel         : true,
        files          : [
            './app/index.php',
            './app/**/*.twig',
            './app/themes/**/*.{js,css}',
            './app/{themes,upload}/**/*.{png,jpg,gif}',
            './app/themes/**/*.{woff,ttf,svg,eot}'
        ]
    });

what is the problem!?

psdcoder commented 8 years ago

Hi, I also have this problem when use tunnel: true and try to call browserSync.stream() or browserSync.reload() before initialize browserSync.

giordanovi commented 8 years ago

I think there is a bug in Browser Sync that start the watch for changes process before initializing Browser Sync.

In my case I solve starting a gulp task dependencies in the callback like this:

gulp.task('serve.sync', ['serve.clean', 'serve.php'], function () {

    var bs = BrowserSync({
        open           : false,
        logConnections : true,
        proxy          : '127.0.0.1:8100',
        online         : true,
        tunnel         : true,
        files          : [
            './app/index.php',
            "./app/themes/**/*.twig",
            './app/themes/**/*.{js,css}', // Javacripts & CSS Assets
            './app/themes/**/*.{woff,ttf,svg,eot}', // Fonts Assets
            './app/{themes,upload}/**/*.{png,jpg,gif}', // Images Assets
        ]
    }, function() {
        gulp.start('theme.serve');
    });
});
shakyShane commented 8 years ago

@giordanovi please provide a small sample project showing this issue as I'm unable to reproduce :)

SSmale commented 6 years ago

I am also having this issue, any help would be appreciated

here is the gulpfile and here is the error message

a reddit post asking for help