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

Turbopack First-Wins Module Registration Installs Wrong Factory For Async Loader With Divergent Bodies In Different Chunks

Turbopack emits the same async-loader module ID with different factories depending on chunk availability. The runtime's first-wins installation causes order-dependent behavior, leading to intermittent dynamic import failures: 'module factory is not available'.

highConfidence 85%Next.jsApp RouterReact Server ComponentsAffected V16.3.3Affected V16.4.0-Canary.12

Origin Analysis

AsyncLoaderModule::asset_ident_for identifies the loader only by target module, ignoring chunk availability, while chunk_item_content generates different loader bodies based on whether the target chunk is already available. Global module ID generation therefore maps divergent factories to the same ID. The runtime installCompressedModuleFactories preserves the first registered factory, so whichever factory is registered first determines behavior, creating a race condition.
1. Clone https://github.com/Stanzilla/turbopack-first-wins-repro 2. Run `npm install` and `npm run verify` 3. The verify script builds the app and runs static/natural/synthetic runtime assertions in both chunk execution orders 4. Observe that dynamic import can fail with `Module <X> was instantiated because it was required from module <Y>, but the module factory is not available.` when the Promise.resolve factory wins before the target factory is registered.

Fixing Code Block

Edge Case Audit

Changing module IDs will invalidate existing persistent caches and may alter chunk hashes across a deploy. Test thoroughly in a large Pages Router app with Turbopack scope hoisting enabled to ensure no new duplicate IDs or bundle size regressions. Rollback by reverting this patch or, as a temporary workaround, set `experimental.turbopackScopeHoisting: false` in next.config.js. Also verify that the availability string is stable and deterministic across builds and platforms to avoid non-deterministic IDs.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state