Search code examples
node.jsgulpbrowserifynode-request

browserify watchify produces errors


I am using gulp, browserify and watchify. Here is my 'scripts' task:

gulp.task('scripts', function() {
    var b = watchify(browserify(paths.app.root + '/client.js', watchify.args));
        b.on('update', bundle);

    return bundle();

    function bundle() {
        return b
            .bundle()
            .pipe(source('bundle.js'))
            .pipe(gulp.dest(paths.build.root + '/scripts'));
    }
});

client.js looks like:

require('request');
alert('1');

where request is node module (http client): https://github.com/request/request

When I run this task and execute the code - everything is fine. The problem starts when I change client.js. When I comment alert('1'), watchify start it's work and bundle() runs again. When I reload the page on the browser, I get the following javascript exception:

Uncaught TypeError: Cannot read property 'version' of undefined

with the following stack trace:

/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/elliptic/lib/elliptic.js.../package.jsonbundle.js:19825  

/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/node_modules/create-ecdh/node_modules/elliptic/lib/elliptic.js.../package.jsonbundle.js:1

/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/node_modules/create-ecdh/ecdh.js.bn.js

/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/node_modules/create-ecdh/inject.js../ecdh

/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/index.js.browserify-aes

/Users/me/project/node_modules/request/lib/helpers.js._process

/Users/me/project/node_modules/request/index.js../lib/cookies

./client.js.request

Any idea what is wrong with browserify / request?


Solution

  • It looks like it is an issue with elliptic, a dependency of browserify. See https://github.com/indutny/elliptic/issues/30

    Hopefully this gets fixed up shortly.

    Edit: It may actually be an issue with browserify. I would try reverting to 8.1.2 and seeing if that helps.