AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Turbopack Dev: Next/Dynamic Preloads A Chunk That Is Never Emitted (404) When The Component Has An Import()

In Next.js dev with Turbopack, using next/dynamic to load a component that contains a plain import() causes the page HTML to reference a chunk that the dev server never emits, resulting in 404 errors on every page load. This affects both App Router (preload link) and Pages Router (script src). The actual dynamic import still works because the emitted loader chunk has a different hash.

mediumConfidence 80%Next.jsAffected V16.3.6Affected V16.4.0-Canary.42

Origin Analysis

collect_next_dynamic_chunks rebuilds the async loader of the next/dynamic import using the parent chunk group's availability info as-is, while make_chunk_group gives the loaders it creates availability_info.in_async_module(). Without nested async availability (the dev default), this flag determines the availability of loaders inside the dynamic chunk group, causing the loader for the nested import() to receive a different ident and consequently a different chunk name on disk than what is recorded in react-loadable-manifest.json.
1. Clone https://github.com/AdzerKI/next-dynamic-async-import-repro 2. Run `npm install` 3. Run `npm run dev` 4. In a second terminal run `npm run check` (loads `/` App Router and `/legacy` Pages Router and requests every chunk referenced in HTML) 5. Observe 404 responses for chunks like `/_next/static/chunks/app_lazy_1i0vu8m4k93tk.js` and `/_next/static/chunks/app_lazy_16oebmc7g56ke.js` while the actual loader chunk has a different hash.

Fixing Code Block

// In packages/next/src/build/turbopack-build/index.ts // Inside collect_next_dynamic_chunks, when rebuilding the async loader // for the next/dynamic import, pass async availability info: const asyncAvailabilityInfo = availabilityInfo.inAsyncModule() const chunkGroup = await make_chunk_group( entrypoint, dynamicEntryPath, dynamicEntryName, 'dynamic', asyncAvailabilityInfo )
The change ensures that the availability info passed to the chunk group creation for the dynamic import's loader matches the async availability used internally by make_chunk_group. This makes the loader's ident and chunk name consistent with what is written to disk, eliminating the 404 for the preload/script chunk.

Edge Case Audit

This fix alters chunk generation behavior and may affect other parts of the Turbopack integration. It should be paired with corresponding changes in the Rust core if availability info is consumed there. After applying, verify that no new 404s or missing chunk errors appear in both dev and build modes, and ensure dynamic imports still function correctly. Rollback should be performed by reverting the change to pass availabilityInfo unchanged, and monitoring the issue queue for any regressions in nested dynamic import handling.

Ecosystem Topology