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
Dynamic Import - Error: Cannot split a chunk that has already been edited #2660
Comments
I can confirm that this works for me in |
For what it's worth, here's my config: https://gist.github.com/arxpoetica/b71700a4893a43e3eabf45810ce4dd6b |
One more clue. I'm realizing this happens when I |
Thanks for discovering this! Based on your repo, I managed to further boil it down to an indeed very basic reproduction using the REPL: As you can see, it is really only the chained dynamic imports that cause it to fail, and you need at least three levels of dynamic imports... I hope to find some time later today or tomorrow to look into the causes and fix it. |
Fix at #2664. Thanks so much, this bug was fairly simple to resolve but had some profound consequences. |
Hello @lukastaegert, Thanks for the fix! Next time, I hope I can do more than one issue ;) Honestly, I was trying to debug on my side, but the time to familiarize myself with the codebase, the fix didn't seem so easy ^.^ Glad to have helped the project and thanks again :) |
No need to worry, the fix looks simple but there was quite a bit of indirection—and familiarity with the algorithm—involved to find it. The thing is the actual issue is that if a dynamic import is chunked together with another module that imports it as well as being dynamically imported by a third module that ends up in another chunk, then rollup tries to rewrite the import statement in two different ways at the same time—which of course fails. The thing is, this situation should never be possible to happen which lead me to investigate why it was happening and finally to the code in the chunk coloring module. However the core issue described is still not fixed. If in the future e.g. we open up the chunking algorithm to allow arbitrary chunk creation, then it will still be possible to recreate this situation and then we really need to fix it, which will be quite a bit more work. In a way, I am glad this caused an issue because otherwise it would have taken us a really long time to even discover that the chunking was broken in such a fundamental way. |
How Do We Reproduce?
Hello,
I created an example here to explain / isolate the issue: https://github.com/jleveugle/rollup-nested-dynamic-imports
I hope it will be understandable :)
In fact, if you try to play with nested dynamic imports, with one of them that is rewritten by a plugin (using magic-string, or something else), your build will failed with rollup@^1.0, while it worked with rollup@^0.66 :)
In my example, I import a fake "bar" (named baar), and my plugin replace baar by bar by using a dynamic import.
Expected Behavior
Build should success, as with rollup@^0.66:
Actual Behavior
Build fails, with an error from
magic-string
.Thanks for your feedback,
The text was updated successfully, but these errors were encountered: