Gaurav Ramanan
Gaurav Ramanan

Reputation: 3643

Bundling files for node.js through browserify does not work

I am using browserify v13.0.0

I have an a.js which just has a module.exports = {a: 1}

And I run browserify as so: browserify --node --debug a.js > bundle.js

In the node REPL,

> require ('./bundle.js')
{}
>

Why the {} ? Shouldn't it give me {a: 1}?

Although I've reduced my problem to the simplest case, this behavior is stopping me from bundling a project involving multiple coffeescript files into a single file for node & browsers.

Ive also tried --bare, --no-builtins, --no-bf

The same thing works with the standalone option. So if I do browserify --node --standalone abc --debug a.js > bundle.js

> require ('./bundle.js')
{a: 1}
>

Standalone can be abc or anything else! It just works

Upvotes: 3

Views: 95

Answers (1)

Ar Es
Ar Es

Reputation: 431

I'm seeing the same thing, and it seems to be connected to the way the UMD header is generated. The standalone parameter sets a property of that name on the root object (which seems to be module.exports when loading the module in node) but i'm not sure yet. I'll have a look at the browserify source for generating the UMD header, and then i'll know more. For now, i'd say stick with the 'standalone' option

Upvotes: 1

Related Questions