turbopackLazyDynamicImports
Compile client-side dynamic imports when they are first requested during development.
The experimental.turbopackLazyDynamicImports option defers compiling client-side dynamic import() targets until the browser first requests them during next dev.
How it works
With turbopackLazyDynamicImports enabled, Turbopack waits to compile the target of a client-side dynamic import() until the browser requests its chunk. Code that the application never imports remains uncompiled during the development session.
For example, the module in this Client Component is compiled when the visitor selects the button:
Good to know:
- The option defaults to
falseand only affects Turbopack duringnext dev. It does not change production builds. - Errors in a deferred module appear when Turbopack first compiles that module.
- Some
next/dynamictargets are still compiled eagerly. - To defer dynamic imports reached while rendering Client Components on the server, use
turbopackLazyDynamicImportsSSR.
Version History
| Version | Changes |
|---|---|
v16.4.0 | experimental.turbopackLazyDynamicImports configuration option added. |