-
Notifications
You must be signed in to change notification settings - Fork 114
Bundling webpack UMD module breaks execution of bundled file #614
Comments
I have changed the webpack configuration of the react-data-grid library to libraryTarget "commonjs2" (see https://webpack.github.io/docs/configuration.html#output-librarytarget), built the project locally and used that dist file in my project => this works perfectly. |
I take it you mean this file - https://npmcdn.com/[email protected]/dist/react-data-grid.js. If I save that file as |
@guybedford Thanks for your fast response! In the meantime I have setup a repo to demonstrate the issue: https://github.com/psurrey/systemjs-umd Can you reproduce it? maybe the issue is with my setup? |
Try adding - This is actually a bug of sorts. I've added a fix to avoid it with systemjs/systemjs@a1decd7. |
Thanks! |
Ok, I did some more debugging and I found that in my example the "main.js" file which should be executed when imported from index.html, is always at the end of the bundled file:
But in the bundle of my "real" application the registerDynamic for "main.js" is called somewhere in the middle of the file:
I suppose it should always be the last module which is registered!? But I have no idea why it isn't in my "real" application... |
Registration order shouldn't be a problem. You could try manually reordering the bundle and see if that recreates the issue, but I somehow doubt that would be it? |
I'm getting a very similar issue over at Angular-CLI: angular/angular-cli#951. After adding After explicitly adding the module format for It strikes me as odd that SystemJS loads |
@filipesilva Thanks for you information! Explicitly specifying the module format fixes the issue also in my case. But stillt it is interesting to understand why the bundled version behaves differently than the dynamically loaded app via SystemJS. |
@psurrey did you have to specify the module formats for all modules? I've an user that is also reporting that |
@filipesilva No, not for all modules. Just for the ones that I've included since it stopped working, which in my case were four react-specific modules. |
I think that we inadvertently fixed this issue when we changed the way we bundle things in this change: angular/angular-cli@5f909aa#diff-93761c20921e800376ba6d58ea4b4988 I just tested it using our momentjs tutorial: https://github.com/angular/angular-cli/wiki/3rd-party-libs#adding-momentjs-library-to-your-project by leaving out the code that adds package format:
In the latest beta (
When running In the latest master version, we only generate one bundle: I'm not sure if my bundling logic was originally flawed or if this represents a bug in the SystemJS builder, but I wanted to leave these details here just in case. Thanks for the great work @guybedford, SystemJS is an awesome tool! |
Thanks @filipesilva for the explanation here. Yes altering the format of moment would have triggered require detection in the source, which may have altered the tree structure. Ordering of the build output is based on the build tree traversal (post-order), so that tree structure changes will alter the order of the output. It doesn't sound like there was a specific bug here, and that things are working now. But if there are still any issues or anything that is unclear, please let me know. |
@guybedford there is a bit that confuses me. In my head, it is not clear why separating a bundle would result into non-functioning bundles - and why setting the module format of one of the used libs would fix the modules. Intuitively I would think that if a single bundle worked, having that bundle split would also work. |
@filipesilva I don't think you were having the same issue here as @psurrey. In order to understand what sort of execution error this was, it may be worth running some debugging on the bundle execution to see if the main entry point is properly executing in the silent error case. Without actively debugging, I can only guess at what the issue might be. If I were to guess I would say that in theory the order of modules in a bundle should not matter. But it is very easy to write code that makes global assumptions where code execution order does matter and changes of order then affect things. These bugs can be sporadic and difficult to track down, making that a possibility here. |
@guybedford I will try to come back with a working, debuggable example repo that does not use Angular-CLI. |
Sure, please do! |
@guybedford I was finally able to set up a working repro of this bug. Knowing that it was related to the dual bundle setup was the missing piece. Here is the repo: https://github.com/filipesilva/systemjs-builder-issue. To repro, clone it, On another console, run Now run Open It seems that something breaks because a module on the second bundle needs something that isn't wrapped in |
Thanks @filipesilva I will go through this when I can. |
@filipesilva it turns out this was a SystemJS bug, I added a fix in systemjs/systemjs@b12938b. |
Oh man I thought I was going crazy with that thing. Glad to hear there's a fix, cheers! |
Hi,
I'm trying to include a dependency into my application that comes bundled using webpack "umd" target (the dependency is https://www.npmjs.com/package/react-data-grid).
I've managed to include it into my app in development mode (modules are loaded by systemjs on the fly asynchronously). In my production build (using angular-cli, I'm developing an app with angular2) this module seems to mess up the bundled file (main.js).
With some debugging effort I was able to figure out that the webpack module is included in the bundle using an anonymous function and not with the usual System.register calls. In systemjs after eval runs past this function the "execute" function property of the current load object is
undefined
:Is it even possible to load such a UMD module packaged by webpack?
Thanks in advance for your answers!
The text was updated successfully, but these errors were encountered: