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

Turbopack Resolves @Emotion/React To Both CJS And ESM Builds In The Same Server Graph, Causing Hydration

Turbopack incorrectly loads both CJS and development ESM builds of @emotion/react in the server rendering graph, leading to dual module instances and hydration mismatches. A workaround is to alias the package to its thin ESM re-export (cjs.mjs) that webpack uses.

highConfidence 92%Next.jsServer Actionsnext buildAffected V16.2.0-Canary.99

Origin Analysis

Turbopack's conditional exports resolution fails to prioritize the 'import' condition and also matches the 'development.module' condition, resulting in both the CJS entry (dist/emotion-react.cjs.js) and the development ESM entry (dist/emotion-react.development.esm.js) being included in the same module graph. This creates multiple instances of the React context and other state, causing hydration errors.
1. Clone the reproduction repository: git clone https://github.com/garronej/turbopack-emotion-dual-module 2. Install dependencies: pnpm install 3. Start the dev server with Turbopack: pnpm run dev-turbopack 4. Open the browser and observe the console hydration error. Compare with pnpm run dev-webpack which shows no error.

Fixing Code Block

Edge Case Audit

Applying this alias will force both server and client builds to use the CJS version of @emotion/react, which may cause issues if the ESM version provides better tree-shaking or has differences in development-specific code. It is recommended to test thoroughly, especially for production builds. Rollback by removing the 'turbopack.resolveAlias' section and using webpack for development instead. The alias path is hardcoded and may break if the package's internal structure changes.

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