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

module.require isn't present #475

Closed
fb55 opened this issue Aug 21, 2013 · 8 comments · May be fixed by browserify/browser-pack#19
Closed

module.require isn't present #475

fb55 opened this issue Aug 21, 2013 · 8 comments · May be fixed by browserify/browser-pack#19

Comments

@fb55
Copy link

fb55 commented Aug 21, 2013

In node.js, module.require is the basis for the require function. Browserify instead directly hands the require function over, without exposing any functionality as module.require.

I'm trying to browserify a module that uses defaultable, which heavily depends on the behavior of node.

It would be awesome if module.require could be at least a reference to the require function.

@ghost
Copy link

ghost commented Aug 21, 2013

I'm not convinced that this feature is worth supporting since it would only enable hacky overriding that probably shouldn't be done in the first place at the expense of extra bytes in every browserify bundle.

@ghost ghost closed this as completed Aug 21, 2013
@fb55
Copy link
Author

fb55 commented Aug 21, 2013

Well, three counter-arguments:

  1. It's browserify's job to act this way when it is intended to be a port of node's module system.
  2. We're talking about a mere 9 bytes here.
  3. There are valid use-cases.

Okay, maybe 1. isn't a great argument as the readme already states that browserify provides a node-style require function, and not "node's module system for the browser".

As for 2., I already submitted a PR to browser-pack, which should implement it. And it's just an additional ,require:r that will be added in the minified source. Still some overhead, but nothing that should lead to a big argument.

Finally, the module I'm trying to compile is iriscouch/cqs. It uses defaultable as a way to provide default options. The actual functionality isn't even a hack, as it uses a documented feature of node's module system and uses the overwritten function for module-wide default propagation.

@jhs
Copy link

jhs commented Sep 5, 2013

@substack, would it be possible for this to be optional or even un-documented?

We might argue about what constitutes "hacky overriding." What I know is that we are using @fb55's code in production and it works well. I agree with your point about spending bytes in every bundle; but I also agree with Felix's point that supporting a documented (stability = 5, locked) feature would be nice.

We will be okay either way, just asking you to reconsider. Thanks.

@janmarek
Copy link

Localization library https://github.com/l20n/l20n.js by Mozilla also depends on module.require.

@rektide
Copy link

rektide commented Dec 23, 2014

I'd like to see the Node.js platform supported in Browserify. Getting files relative to modules is important. 😟

Also, in this particularly awful case, we're using a Browserify bundle inside a require.js webapp; require.js gracelessly stomps the require variable (gee it'd be nice if these module-level variables more locally scoped by Browserify (& thus protected)). I'd expected module.require to be a cute dodge around the problem, but alas, tragedy.

Also missing: module.id, module.filename, module.loaded, module.parent, module.children.

@fogine
Copy link

fogine commented Jul 30, 2018

I'm confused, since valid use of nodejs PUBLIC API is considered hacky approach ?!
This should be revisited as of 2018.
if that's an argument for you, webpack supports module.require

@montamal
Copy link

This is still an issue. browserify/browser-pack#19

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

Successfully merging a pull request may close this issue.

7 participants