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

10.2.4 bug: b.require and --standalone #1305

Open
mattfysh opened this issue Jun 13, 2015 · 6 comments
Open

10.2.4 bug: b.require and --standalone #1305

mattfysh opened this issue Jun 13, 2015 · 6 comments

Comments

@mattfysh
Copy link

It looks like the 10.2.4 release has changed the order of the CLI entry file and b.require files when they are pushed through the pipeline to "label", resulting in the wrong module being exported ie. _bpack.standaloneModule.
e.g. if running with browserify src/main.js -s app and also using a plugin that sets b.require(config.js', {expose: 'config'}), looking for window.app now returns the config.js exports, instead of src/main.js exports

@mattfysh
Copy link
Author

current workaround

b.pipeline.get('deps').push(through(function(row) {
    if (row.expose && !row.entry) {
        delete row.expose;
    }
    this.queue(row);
}));

@zertosh
Copy link
Member

zertosh commented Jun 14, 2015

Can you provide a repro case?

@mattfysh
Copy link
Author

np! here it is:

var b = require('browserify')({
    standalone: 'app'
});
b.add('a.js');
b.require('./b.js')
b.bundle().pipe(process.stdout);

With 10.2.4, window.app = B, and with 10.2.3, window.app = A

@zertosh
Copy link
Member

zertosh commented Jun 23, 2015

sorry @mattfysh for the delay. this actually changed from 8.1.3 to 9.0.0 (#1077). I'm tempted to call this a bug, @jmm you made that change, what do you think?


For context, this happens because the module that is exposed by standalone is the last entry or expose module. https://github.com/substack/node-browserify/blob/f9c2561/index.js#L711

@jmm
Copy link
Collaborator

jmm commented Jun 24, 2015

@zertosh I'll look into it and report back.

@jmm
Copy link
Collaborator

jmm commented Jun 24, 2015

@zertosh I'm not sure what's happening with @mattfysh's result. I tried the API repro and I get B as the standalone every time. In 10.2.3 it's identified as ./b.js and in 10.2.4 as /some/abs/path/b.js. So it sounds like there's some other non-determinism happening there. What OS and node version @mattfysh?

@zertosh I didn't trace this in detail, but I looked at the line you highlighted and I can see how my change in #1077 would affect that. This is another example of complications arising from the row props being poorly specified.

Is it a bug? Not sure. I have some questions about how b.require() and exposure is fundamentally supposed to work.

  1. What is the point of doing?

    // No `expose`
    b.require('./b.js')
  2. Either of these should work for standalone, right?:

    b.add('./a.js');
    
    // OR
    
    b.require('./b.js', {expose: 'B'});

    So if you have...

    b.add('./a.js');
    b.require('./b.js', {expose: 'B'});

    Which is supposed to "win" as the standalone (first, last, other)? I've considered and discussed this before (.add or .require expose option hijacks entry module #1120) and I think a more expressive API may make sense (like a standalone row prop instead of constructor option).

  3. Is exposed name from b.require() supposed to be available inside bundle? #1137

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

No branches or pull requests

3 participants