question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tunnel Issue on reload()

See original GitHub issue

I am using 2.11.1 BrowserSync and it is not tunneling the custom domain. Here’s the error

/Users/ahmadawais/Documents/Websites/wpgulp.dev/wp-content/themes/wpgulp-theme/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/ahmadawais/Documents/Websites/wpgulp.dev/wp-content/themes/wpgulp-theme/node_modules/browser-sync/lib/browser-sync.js:668:22)
    at Timer.listOnTimeout (timers.js:92:15)

Here’s the gulp file

/**
 * Gulpfile.
 *
 * A simple implementation of Gulp.
 *
 * Implements:
 *          1. Sass to CSS conversion
 *          2. JS concatenation
 *          3. Watch files
 *
 * @since 1.0.0
 * @author Ahmad Awais (@mrahmadawais)
 */

 /**
  * Configuration.
  *
  * Project Configuration for gulp tasks.
  *
  * Edit the variables as per your project requirements.
  */

var project             = 'WPGulpTheme'; // Project Name.
var projecturl          = 'wpgulp.dev'; // Project URL. Could be something like localhost:8888.
var tunnelname          = project.toLowerCase(); // Ignorable/Optional: tunnel name is lowercase of project if you choose to use it.


var styleSRC            = './assets/css/style.scss'; // Path to main .scss file
var styleDestination    = './'; // Path to place the compiled CSS file
// Defualt set to root folder


var jsVendorSRC         = './assets/js/vendors/*.js'; // Path to JS vendors folder
var jsVendorDestination = './assets/js/'; // Path to place the compiled JS vendors file
var jsVendorFile        = 'vendors'; // Compiled JS vendors file name
// Default set to vendors i.e. vendors.js


var jsCustomSRC         = './assets/js/custom/*.js'; // Path to JS custom scripts folder
var jsCustomDestination = './assets/js/'; // Path to place the compiled JS custom scripts file
var jsCustomFile        = 'custom'; // Compiled JS custom file name
// Default set to custom i.e. custom.js

// Watch files paths.
var styleWatchFiles     = './assets/css/**/*.scss'; // Path to all *.scss files inside css folder and inside them
var vendorJSWatchFiles  = './assets/js/vendors/*.js'; // Path to all vendors JS files
var customJSWatchFiles  = './assets/js/custom/*.js'; // Path to all custom JS files


/**
 * Load Plugins.
 *
 * Load gulp plugins and assing them semantic names.
 */
var gulp         = require('gulp'); // Gulp of-course

// CSS related plugins.
var sass         = require('gulp-sass'); // Gulp pluign for Sass compilation
var minifycss    = require('gulp-uglifycss'); // Minifies CSS files
var autoprefixer = require('gulp-autoprefixer'); // Autoprefixing magic
const AUTOPREFIXER_BROWSERS = [
    'last 2 version',
    '> 1%',
    'ie >= 9',
    'ie_mob >= 10',
    'ff >= 30',
    'chrome >= 34',
    'safari >= 7',
    'opera >= 23',
    'ios >= 7',
    'android >= 4',
    'bb >= 10'
  ]; // Browsers you care about for autoprefixing. Browserlist https://github.com/ai/browserslist


// JS related plugins.
var concat       = require('gulp-concat'); // Concatenates JS files
var uglify       = require('gulp-uglify'); // Minifies JS files

// Utility related plugins.
var rename      = require('gulp-rename'); // Renames files E.g. style.css -> style.min.css
var sourcemaps  = require('gulp-sourcemaps'); // Maps code in a compressed file (E.g. style.css) back to it’s original position in a source file (E.g. structure.scss, which was later combined with other css files to generate style.css)
var notify      = require('gulp-notify'); // Sends message notification to you
var browserSync = require('browser-sync').create(); // Reloads browser and injects CSS. Time-saving synchronised browser testing.
var reload      = browserSync.reload; // For manual browser reload.


/**
 * Task: `browser-sync`.
 *
 * Live Reloads, CSS injections, Localhost tunneling.
 *
 * This task does the following:
 *      1.
 */
 gulp.task( 'browser-sync', function() {



    browserSync.init( {

        // Read here http://www.browsersync.io/docs/options/
        proxy: projecturl,

        // Use a specific port (instead of the one auto-detected by Browsersync).
        // port: 3000,

        // Tunnel the Browsersync server through a random Public URL
        // E.g. http://randomstring23232.localtunnel.me
        tunnel: true,

        // Attempt to use the URL "http://project.localtunnel.me"
        // It uses the project name in lowercase.
        // This can be a cusotm subdomain
        // E.g. "tunnel: myname," will be "http://myname.localtunnel.me"
        tunnel: tunnelname,


        // Inject CSS changes
        injectChanges: true,

        // Log information about changed files
        // logFileChanges: true,

        // Stop the browser from automatically opening
        // open: false,


    } );
 });


/**
 * Task: styles
 *
 * Compiles Sass, Autoprefixes it and Minifies CSS.
 *
 * This task does the following:
 *      1. Gets the source scss file
 *      2. Compiles Sass to CSS
 *      3. Writes Sourcemaps for it
 *      4. Autoprefixes it and generates style.css
 *      5. Renames the CSS file with suffix .min.css
 *      6. Minifies the CSS file and generates style.min.css
 *      7. Injects CSS or reloads the browser via browserSync
 */
gulp.task('styles', function () {
    gulp.src( styleSRC )
        .pipe( sourcemaps.init() )
        .pipe( sass( {
            errLogToConsole: true,
            outputStyle: 'compact',
            //outputStyle: 'compressed',
            // outputStyle: 'nested',
            // outputStyle: 'expanded',
            precision: 10
        } ) )
        .pipe( sourcemaps.write( { includeContent: false } ) )
        .pipe( sourcemaps.init( { loadMaps: true } ) )
        .pipe( autoprefixer( AUTOPREFIXER_BROWSERS ) )

        .pipe( sourcemaps.write ( styleDestination ) )
        .pipe( gulp.dest( styleDestination ) )


        .pipe( rename( { suffix: '.min' } ) )
        .pipe( minifycss( {
            maxLineLen: 10
        }))
        .pipe( gulp.dest( styleDestination ) )
        .pipe( browserSync.stream() )
        .pipe( notify( { message: 'TASK: "styles" Completed!', onLast: true } ) )
});


/**
 * Task: vendorJS
 *
 * Concatenate and uglify vendor JS scripts.
 *
 * This task does the following:
 *      1. Gets the source folder for JS vendor files
 *      2. Concatenates all the files and generates vendors.js
 *      3. Renames the JS file with suffix .min.js
 *      4. Uglifes/Minifies the JS file and generates vendors.min.js
 */
gulp.task( 'vendorsJs', function() {
    gulp.src( jsVendorSRC )
        .pipe( concat( jsVendorFile + '.js' ) )
        .pipe( gulp.dest( jsVendorDestination ) )
        .pipe( rename( {
            basename: jsVendorFile,
            suffix: '.min'
        }))
        .pipe( uglify() )
        .pipe( gulp.dest( jsVendorDestination ) )
        .pipe( notify( { message: 'TASK: "vendorsJs" Completed!', onLast: true } ) );
});


/**
 * Task: customJS
 *
 * Concatenate and uglify custom JS scripts.
 *
 * This task does the following:
 *      1. Gets the source folder for JS custom files
 *      2. Concatenates all the files and generates custom.js
 *      3. Renames the JS file with suffix .min.js
 *      4. Uglifes/Minifies the JS file and generates custom.min.js
 */
gulp.task( 'customJS', function() {
    gulp.src( jsCustomSRC )
        .pipe( concat( jsCustomFile + '.js' ) )
        .pipe( gulp.dest( jsCustomDestination ) )
        .pipe( rename( {
            basename: jsCustomFile,
            suffix: '.min'
        }))
        .pipe( uglify() )
        .pipe( gulp.dest( jsCustomDestination ) )
        .pipe( notify( { message: 'TASK: "customJs" Completed!', onLast: true } ) );
});

 /**
  * Watch Tasks.
  *
  * Watches for file changes and runs specific tasks.
  */

 gulp.task( 'default', ['styles', 'vendorsJs', 'customJS', 'browser-sync'], function () {
    gulp.watch( styleWatchFiles, [ 'styles' ] );
    gulp.watch( vendorJSWatchFiles, [ 'vendorsJs', reload ]  );
    gulp.watch( customJSWatchFiles, [ 'customJS', reload ]  );
 });


What am I missing?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
marek-sajicommented, May 11, 2016

@ahmadawais I bumped onto the same error. Returning a stream in gulp task fixed that for me. Like so:

  gulp.task('styles', function () {
-     gulp.src( styleSRC )
+     return gulp.src( styleSRC )
          .pipe( sourcemaps.init() )
0reactions
shakyShanecommented, Nov 20, 2016

@wesbos this still should not cause an error though - calling Browsersync methods without a running instance should simply no-op.

Could you provide a small example?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Common L2L and Remote Access IPsec VPN ...
This document contains the most common solutions to IPsec VPN problems. ... Problem. Solution. Unable to Pass Traffic Across VPN Tunnel. Problem. Solution....
Read more >
Issue #330: ipsec reload creates new tunnels ... - strongSwan
I have a single tunnel, and if I issue 'ipsec reload' it ends up appearing multiple times in 'ipsec status'. I'm not changing...
Read more >
Reload a Html file on my webview with tunnel interaction
I have a problem, right now in reloading a html file on my webview component. So, basically, when i run the application, my...
Read more >
Tunnel options for your Site-to-Site VPN connection
Learn about the different tunnel options for your Site-to-Site VPN connection. ... Each Site-to-Site VPN connection has two tunnels, with each tunnel using ......
Read more >
IpsecTunnel api refresh - LIVEcommunity - 280771
Looks like the problem is that you haven't imported pandevice.network at all. Once you do that, you should be ok.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found