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.

node options flag not recognized using gulp and browserify

See original GitHub issue

Browserify shims the core http module with stream-http for browser compatibility, and has a --node flag to prevent this from happening. However, I am unable to do this through gulp, or the documentation does not explain how. I would like to perform the following and not have the stream-http module included in my final browserify bundle:

gulp.task('scripts:server', () => {

    const bundler = browserify(
        'build/source/server.js',
        { 
            debug: true,
            node: true,
        }
    );

    const bundlerError = (err) => {
        console.error(err);
    };

    return bundler.bundle()
        .on('error', bundlerError)
        .pipe(source('server.js'))
        .pipe(buffer())
        .pipe(gulp.dest('dist'));
});

I can see the bare: true and browserField: false do something if I pass them into browserify as options, however, node: true seems to have no effect.

If I run browserify as a command and not through gulp, it works just fine:

browserify --node build/source/server.js -o dist/server.js

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:14

github_iconTop GitHub Comments

6reactions
tlopocommented, Apr 21, 2016

Through the api the parameters necessary to replicate --node are:

        {
            browserField : false,
            builtins : false,
            commondir : false,
            insertGlobalVars : {
                process: undefined,
                global: undefined,
                'Buffer.isBuffer': undefined,
                Buffer: undefined 
            }
        }

That’s how my gulp task looks like:

    gulp.task('default', function() {
        return browserify('./index.js',
        {
            browserField : false,
            builtins : false,
            commondir : false,
            insertGlobalVars : {
                process: undefined,
                global: undefined,
                'Buffer.isBuffer': undefined,
                Buffer: undefined 
            }
        }
    )
        .bundle()
        .pipe(source('bundle.js'))
        .pipe(gulp.dest('./'));
    });

Hope this helps someone.

1reaction
tanguy2mcommented, Feb 24, 2017

I faced the same issue using browserify to bundle my javascript modules in an Electron app. I ended-up with the following options:

  ignoreMissing: true,
  builtins: false,
  commondir: false,
  browserField: false,
  detectGlobals: false
Read more comments on GitHub >

github_iconTop Results From Across the Web

Gulp + Browserify task not working (no output) - Stack Overflow
I'm now maintaining a repository which collecting all the gulp tasks I use in daily work. This is the browserify task code. var...
Read more >
Gulp + Browserify - Viget
I picked up Gulp and Browserify just days after learning Grunt ... The first time using CommonJS (Node) modules was a breath of...
Read more >
Webpack or Browserify & Gulp: Which Is Better? - Toptal
In this article, Toptal Freelance Software Engineer Eric Grosse shows us how various combinations of the popular tools Webpack, Browserify, Gulp and Npm...
Read more >
Browserify
First install node, which ships with npm. ... Here is a tutorial on how to use Browserify on the command line to bundle...
Read more >
rollup.js
To use Rollup with a configuration file, pass the --config or -c flags: ... with NPM, compiling code with Babel, working with JSON...
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