-
Notifications
You must be signed in to change notification settings - Fork 671
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
CommonJS wrapper doesn't like being bundled #833
Comments
Sounds like it could be two different things:
The main bug in 2) is that it should not really matter what order the define() calls are in, but unfortunately looks like a bug got in where the order of dependencies is assumed to be least dependencies to more dependencies (so assuming define('foo') would come before define('bar') in this example). As for workarounds, if it is just an issue of a build and the only issue is 2), rawText config could be used to seed the 'foo' value. It would likely mean a duplicate define('foo') in the output, but that is fine. However, if the real code has an actual factory function definition for foo, and it is not just a You could use the onBuildRead/onBuildWrite hooks to seed some stub define('foo') at the top of the file with onBuildRead just to get it the optimizer to see it first, then maybe remove that stub with onBuildWrite. Or if you have control over how that bar.js file concatenates the modules, ordering them where leaf dependencies are first should avoid the bug. However, if there is a UMD wrapper around the define() calls (issue 1), then it would be good to get a more fleshed out example of the file's structure. |
For context, the actual file I'm trying to bundle is https://github.com/cujojs/when/blob/master/es6-shim/Promise.js. The problem starts at https://github.com/cujojs/when/blob/ed92496f0db26f72b3471b65440023b42d92cedd/es6-shim/Promise.js#L24. |
Thanks for the example file. It was indeed the UMD detection not correctly identifying the UMD wrapper. I filed requirejs/requirejs#1389 to address the separate, unrelated issue of allowing out of order define() calls (the 2) issue above), just happened across that separate bug while looking into this one. The fix for this issue will be in 2.1.20. I am not sure yet when I will publish it, but given that UMD wrapped files have been showing up more often, I am thinking on the order of a week or so. Do not want to go too long without this fix going out. I may even get it out this weekend, just want to scrub through some other open issues before locking down the release. If you want a fix today, the r.js master snapshot contains the fix: https://raw.githubusercontent.com/jrburke/r.js/master/dist/r.js For this specific fix on top of 2.1.19 (where the above link will change as master changes): https://raw.githubusercontent.com/jrburke/r.js/3407e2d45ff6dfd268b8e3e13f7c712180daf6ad/dist/r.js |
Thank you very much for the fast response! :-) On Fri, 17 Jul 2015 at 18:17 James Burke notifications@github.com wrote:
|
I have a third party script which is an optimized AMD file that contains a CommonJS wrapper:
When I try to bundle this file into my own file:
r.js doesn't notice that
foo
is already defined within thebar
file, leading to:I'm guessing this is because r.js has to perform static analysis of the CommonJS wrapper. What do you recommend to work around this issue?
The text was updated successfully, but these errors were encountered: