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

Turbopack: ESM Worker With Import.Meta.Url Path Fails With 'Cannot Find Module'

Using new Worker() with a path derived from import.meta.url in an ESM package under Next.js Turbopack throws 'Cannot find module', even though the worker file exists. The CommonJS version with __dirname works. This is a regression from Next.js 16.0.2.

highConfidence 80%Next.jsHydrationApp RouterAffected V16.1.0Affected V16.2.0Affected V16.3.0Affected V16.3.7Affected V16.4.0-Canary.52

Origin Analysis

Turbopack's worker asset lookup table is keyed by file names (or simple relative paths), but the runtime argument constructed from import.meta.url is a full absolute file URL or absolute filesystem path, which does not match any key. This mismatch causes the worker module resolution to fail.
1. Clone https://github.com/orleib-lab/turbopack-worker-import-meta-repro\n2. Run npm install\n3. Run npm run build && npm start\n4. Open /api/esm and observe 'Cannot find module'\n5. Open /api/cjs and observe successful response

Fixing Code Block

Edge Case Audit

This workaround may not work if Turbopack re-emits the worker file under a different name or location; absolute paths may still fail if the worker registry uses original filenames. Revert to the original code once the upstream issue is resolved. Test in production build and dev before deploying.

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