josephg / node-browserchannel

An implementation of a google browserchannel server in node.js
287 stars 47 forks source link

Uncaught TypeError: fs.statSync is not a function #57

Open kharandziuk opened 9 years ago

kharandziuk commented 9 years ago

my main.js just import the library: var BCSocket = require('browserchannel').BCSocket;

I compile file with gulpfile below

var gulp = require('gulp'),
  browserify = require('browserify'),
  del = require('del'),
  source = require('vinyl-source-stream'),
  babelify = require('babelify');

var paths = {
    srcJs: ['./main.js'],
    js: ['./bundle.js']
}

gulp.task('clean', function(done){
    del(['build'], done)
})

gulp.task('js', ['clean'], function() {
        browserify({debug: true})
        .transform(babelify)
        .require('./main.js', {entry: true})
        .bundle()
        .on("error", function (err) { console.log("Error: " + err.message); })
        .pipe(source('bundle.js'))
        .pipe(gulp.dest('./static/'));
})

// Rerun tasks whenever a file changes.
gulp.task('watch', ['js'], function() {
    gulp.watch(paths.srcJs, ['js']);
});

When I open file in browser I achieve an error Uncaught TypeError: fs.statSync is not a function.

What may cause the problem?

kharandziuk commented 9 years ago

Ok, sorry. Now I understand the issue the library isn't browserify compatible at all

DetweilerRyan commented 9 years ago

The issue isn't that the library is not browserify compatible (indeed it is compatible). The issue is that the BCSocket isn't isomorphic/universal (i.e. there are two different implementations of BCSocket: one of the server and one for clients).

on the server use:

var BCSocket = require('browserchannel').BCSocket;

and on the client use:

var BCSocket = require('browserchannel/dist/bcsocket-uncompressed').BCSocket;
var socket = new BCSocket( null, {reconnect: true} );

Hope this helps.