-
Notifications
You must be signed in to change notification settings - Fork 110
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
v2 addons don't always get ideal execution order #504
Comments
Thanks for the great bug report. I see what's happening here. It involves the interaction of three things:
Should we fix loader.js? Maybe, but I bet people are accidentally relying on this wrong execution order. This bug would not occur under embroider because there ember-tracked-storage-polyfill will get rewritten into a v2 addon and the dependencies between tracked-redux and ember-tracked-storage-polyfill are all handled by webpack, not loader.js. So I think your best bet is simonihmig/tracked-redux#123. |
So this was apparently the wrong expectation I had...
Got it. As said above, I thought I can expect the imports to be resolved synchronously and under any circumstance. But in hindsight I see why that cannot work in the case of cycles. Should maybe start to study the spec... 😏 Thanks so much for taking the time to go through this in detail! |
I went to reproduce this loader.js behavior in isolation and realized it is a problem with the way ember-auto-import is interacting with loader.js. When ember-auto-import isn't involved, loader.js does get the order right here. ember-auto-import manages the boundary between loader.js and webpack's loader, and up until recently that has always been one-way. You would auto-import non-ember packages and they wouldn't in turn depend on any ember packages owned by loader.js. But now that v2 addons are handled by ember-auto-import, the relationship goes both ways. We register a stub with loader.js that gets the package from webpack, but our stub doesn't expose any dependency list to loader.js, which means loader.js can't figure out the ideal place that our stub should fit in the execution order. So it may run before some of its dependencies, as if there was a cycle. |
This is probably fixable but it's not easy. We could run the full Analyzer over v2 addons to know in advance what they're importing, but that's quite expensive and we don't really even have a place where we could easily do it from. Normally they don't get touched until webpack is traversing them, and the only reason webpack is traversing them is because we already wrote the stub modules in webpack's input. We could discover the dependencies by side-effect from the externalsHandler, but then we have to do something tricky to get that information into the build, since at this point all our inputs to webpack have been provided. Maybe a custom webpack plugin can add the extra information at the end, and then our runtime code would read that dependencies info at the point where it's calling |
I just ran in to this issue with Is the path forward to make sure all dependencies of v2 addons are also v2 addons? in that we need |
well there has to be something fishy with my setup, because all my other v2-addon consuming projects test non-embroider builds, and they worked with |
That is consistent with this issue though. It's evaluation-order dependent. Lots of projects won't hit it, purely out of luck. |
Fixes #504. Removes earlyBootSet, because that was a hack for the lack of this feature. earlyBootSet never actually worked correctly anyway. I'm considering this a bugfix and not a breaking change, since nobody could reliably use that setting anyway.
Fixes #504. Removes earlyBootSet, because that was a hack for the lack of this feature. earlyBootSet never actually worked correctly anyway. I'm considering this a bugfix and not a breaking change, since nobody could reliably use that setting anyway.
Fixes an issue where running the tests locally does not work. see: embroider-build/ember-auto-import#504
Fixes an issue where running the tests locally does not work. see: embroider-build/ember-auto-import#504
Fixes an issue where running the tests locally does not work. see: embroider-build/ember-auto-import#504
I pulled my hair with some very broken behavior in an app. Luckily I was able to create a minimal reproduction. So this is a super weird issue, be prepared...
Context
I believe this has to do with the following circumstances:
tracked-redux
, directly or through some other addon), and it also(!) imports the v1 addon (ember-tracked-storage-polyfill
, again directly or through some other addon)ember-tracked-storage-polyfill
) module is loaded (by loader.js) the first time through the v2 addon.Reproduction
tracked-redux
is importedtracked-redux
importsgetValue
fromember-tracked-storage-polyfill
and assigns it to an aliasconsumeTag
hereember-tracked-storage-polyfill
(webpack-require) is an empty object, soconsumeTag
is undefined. See this screenshot while debugging:require
by loader.js, you can see that the module is in pending state, and indeed the returnedmod.module.exports
is just an empty object:consumeTag
alias is first used, this fails of course with "consumeTag is not a function", as you can also see in CIember-tracked-storage-polyfill
have actually been resolved. The code still fails of course due to the fact that an alias has been assigned eagerly, which is still undefined. See:More to come
I was actually able to workaround that problem, however in weird and unexpected ways...
ember-tracked-storage-polyfill
) from the app, so that only the v2 addon imports it, this resolves the issue. This scenario is replicated in "Fix" broken import by removing other import simonihmig/broken-import-reproduction#2Both changes illustrated in those PRs make the test pass! 🤔
Tbh I am not really sure where the bug is, if it's eai, or maybe even loader.js. Though I debugged quite a bit through those module resolution code of loader.js, I didn't really follow its inner logic. But as it seems this is related in some way to v2 addons entering the playing field here, I thought I file it here first!
The text was updated successfully, but these errors were encountered: