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

Turbopack Edge Route Handler Build Fails When CacheHandlers Is Set

When using Turbopack, Next.js builds fail for edge route handlers if the `cacheHandlers` configuration is provided. Webpack builds succeed. The regression was introduced in PR #91236 (commit a6b36200f) which only covered the singular `cacheHandler` in edge path wiring.

highConfidence 65%Next.jsApp RouterHydrationAffected V16.5.0-Canary.4

Origin Analysis

The Turbopack build's environment definition does not forward the plural `cacheHandlers` configuration to the edge runtime, causing edge route handlers to lack the necessary cache handler reference and fail during compilation or runtime.
1. Clone the reproduction repo: https://github.com/oskari/next-bug-repros/tree/main/edge-route-cache-handlers 2. Install dependencies with `pnpm install` 3. Run `pnpm build` (Turbopack) and observe failure 4. Run `pnpm next build --webpack` and observe success

Fixing Code Block

Edge Case Audit

This patch assumes that `getDefineEnv` already accepts a `cacheHandlers` property; if not, the function signature must be updated accordingly. Validate that the serialized `cacheHandlers` object does not contain functions or circular references that could break the DefinePlugin. Test thoroughly with both Turbopack and webpack, and verify edge route handlers that use caching features. Rollback is straightforward by reverting this single line addition.

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