-
Notifications
You must be signed in to change notification settings - Fork 27k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Dev Server Eagerly Compiles Dynamic Imports #18819
Comments
This is how dynamic imports work in webpack unfortunately. cc @sokra |
I was afraid of that. Any idea if Webpack 5 changes this behavior? I can't find anything that specifically references it in their changelog. |
Webpack will always compile dynamic imports at build time and that behavior will probably never change. On The name |
It sounds like the only way to reduce load times is to reduce the amount of dynamic imports used by each page. I'll focus on splitting this very large page up into multiple smaller NextJS pages. Thank you for your feedback! Closing this issue since the dev server load times are inherent to Webpack rather than NextJS. |
Going to keep this open as we can potentially tackle it in the future. |
FWIW this seems to be on the roadmap for Webpack 5. This webpack/webpack#8644 discussion has some interesting information. Including an npm package which I haven't tested, that defaults all dynamic imports to Ideally, if native support for |
I don't think Tagging an import as The performance gains in the linked issue involve chunk-creation overhead, not the time necessary to actually parse the files that make up the chunk in the first place. |
Please verify that your issue can be recreated with Why was this issue marked with the
|
Still happening (on latest Next 13.0.7 with classic Good question at this point is: Is it fixed with Turbopack? Or with the latest |
same issue, how do you solve this now? @ddgromit |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Bug report
Describe the bug
The dev server is eagerly following dynamic imports in a page and compiling them before they are requested.
One of my pages does one of a few dynamic imports depending on the type of object its viewing. Each dynamic import in the page is reasonably sized but put together they cover almost the entire codebase. Since the dev server is compiling them all on the first page load, just to build that page (even before the page loads and can do the import) the dev server takes about 2-3 minutes of compilation time and node racks up over 4gb of memory.
The bundle chunks are actually generated correctly both in dev and production, and the code isn't actually loaded by the browser until the dynamic import is called. However it seems the dev server has to compile or process the entire tree of dynamic imports just to display the page for the first time.
To Reproduce
Requesting this page responds in seconds:
Whereas this page takes minutes, even though the dynamic import is never called:
Expected behavior
Dynamically imported files should not be compiled by the dev server until the client requests them.
Screenshots
System information
The text was updated successfully, but these errors were encountered: