Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kharandziuk opened this issue May 21, 2015 · 2 comments
Open

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

kharandziuk opened this issue May 21, 2015 · 2 comments

Comments

@kharandziuk
Copy link

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
Copy link
Author

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

@DetweilerRyan
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants