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

Turbopack ServerExternalPackages Relative Symlinks Break In Multi-Stage Docker Builds

Next.js 16 with Turbopack generates relative symlinks in .next/node_modules that overshoot the filesystem root when .next is copied to a shallower directory depth in multi-stage Docker builds, causing runtime module resolution failures. Additionally, hashed module names require NODE_PATH to resolve.

highConfidence 85%Next.jsTurbopackRoute HandlersHydrationAffected V16.1.6

Origin Analysis

Turbopack resolves serverExternalPackages by creating relative symlinks from .next/node_modules/<pkg>-<hash> to the build-time hoisted node_modules (e.g. ../../../node_modules/pino), which break when the .next directory is moved to a different filesystem depth; the emitted require() statements also use hashed names that Node.js cannot resolve without NODE_PATH.
1. Clone https://github.com/kyeb/turbopack-symlink-repro 2. Run docker build -t repro . 3. Run docker run -p 3000:3000 repro 4. curl http://localhost:3000/ 5. Observe HTTP 500 with Error: Cannot find module 'pino-28069d5257187539'

Fixing Code Block

Edge Case Audit

This is a temporary mitigation, not an upstream fix. It assumes package names can be derived by stripping a trailing hexadecimal hash; packages with digits or names that match this pattern may be misdetected. It also requires manual execution and does not cover nested dependencies. The NODE_PATH workaround may leak into other module resolution contexts. Rollback: remove the script and NODE_PATH, and restore original symlinks. Upgrading Next.js to a version where Turbopack generates absolute or .next-relative symlinks is the recommended long-term resolution.

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