-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Incorrect chunking when code has top-level await #4708
Comments
Thanks for spotting. I knew that we were not handling TLA execution order correctly, but I did not consider you could create deadlocks this way. The best we can do is to create more chunks, I will need to think about this a little. |
I'm having the same problem and it's making us tired :/ |
@bluwy I know its been a while but did you figure out a way to bypass this issue? |
I haven't tested, but following the repro, setting I also started to attempt a fix recently though, so maybe this will be fixed by itself (if I can figure out the algorithm). |
Yes, thanks for that. |
It seems like it's part of the ESM spec that it fails silently. Here's a stackblitz example of the deadlock happening in browsers too. If you run it through something like Bun it seems to work, maybe because it's not following the spec exactly. |
I tried looking into it but it's a little complicated than expected. I can fix the repro's specific case by skipping deleting the shared chunks' dependent entries (used for optimization) at here. But it's not the true fix with a more complex TLA loop like in withastro/astro#8598, where shared code are spreaded more. The true fix likely lies in the very first step at rollup/src/utils/chunkAssignment.ts Lines 151 to 153 in 5950fc8
initialChunks should have the TLA module in its own chunk, plus further optimizations need to keep in mind to not merge their chunk to this TLA chunk.
|
It looks like in Node 22, there's now a warning logged instead of silently working: Warning: Detected unsettled top-level await at file:///Users/bjorn/Work/test/main-3d8a8f11.js:3
const mod = await import('./module_1-ae086170.js'); I found this from nodejs/node#55468 |
Rollup Version
3.2.5 (also happens in v2)
Operating System (or Browser)
macos
Node Version (if applicable)
No response
Link To Reproduction
https://rollupjs.org/repl/?version=3.2.5&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMCU3QiUyMHJlbmRlciUyMCU3RCUyMGZyb20lMjAnLiUyRmZyYW1ld29yay5qcyclNUNuJTVDbmNvbnN0JTIwbW9kJTIwJTNEJTIwYXdhaXQlMjBpbXBvcnQoJy4lMkZtb2R1bGVfMS5qcycpJTVDbmNvbnN0JTIwc29tZXRoaW5nJTIwJTNEJTIwYXdhaXQlMjByZW5kZXIoJ3RoaW5nJyklNUNuJTVDbmV4cG9ydCUyMCU3Qm1vZCUyQyUyMHNvbWV0aGluZyU3RCUyMiUyQyUyMmlzRW50cnklMjIlM0F0cnVlJTdEJTJDJTdCJTIybmFtZSUyMiUzQSUyMm1vZHVsZV8xLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMCU3QiUyMHJlbmRlciUyMCU3RCUyMGZyb20lMjAnLiUyRmZyYW1ld29yay5qcyclNUNuJTVDbmV4cG9ydCUyMGNvbnN0JTIwaHRtbCUyMCUzRCUyMHJlbmRlcignJTNDaDElM0V0ZXN0JTNDJTJGaDElM0UnKSUyMiUyQyUyMmlzRW50cnklMjIlM0FmYWxzZSU3RCUyQyU3QiUyMm5hbWUlMjIlM0ElMjJmcmFtZXdvcmsuanMlMjIlMkMlMjJjb2RlJTIyJTNBJTIyZXhwb3J0JTIwZnVuY3Rpb24lMjByZW5kZXIoc3RyKSUyMCU3QiUyMHJldHVybiUyMHN0ciUyMCU3RCUyMiU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlMjJmb3JtYXQlMjIlM0ElMjJlcyUyMiUyQyUyMm5hbWUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmFtZCUyMiUzQSU3QiUyMmlkJTIyJTNBJTIyJTIyJTdEJTJDJTIyZ2xvYmFscyUyMiUzQSU3QiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE
Expected Behaviour
The
framework.js
file should have it's own build chunk in the output, andmodule_1-ae086170.js
imports from that chunk instead, because of the top-level await inmain-3d8a8f11.js
Actual Behaviour
module_1-ae086170.js
imports a function fromframework.js
throughmain-3d8a8f11.js
(inlined). This has problems becausemain-3d8a8f11.js
contains top-level awaits that in turn waits formodule_1-ae086170.js
(loop).Running the output in nodejs silently fails (node 22 starts logging a warning). Here's a stackblitz of the REPL's output copied. Run
node test.js
in the terminal to see nothing printed in the console.The text was updated successfully, but these errors were encountered: