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

Standalone Build Omits Source Maps For Server Chunks

Next.js standalone output does not copy .map files for server chunks, causing sourceMappingURL comments to point to missing maps when running with --enable-source-maps.

mediumConfidence 85%Next.jsReact Server ComponentsRoute HandlersApp RouterAffected V16.1.5Affected V16.2.0-Canary.37

Origin Analysis

The standalone build copy step filters out .map files from the traced files, so the copied JavaScript files reference source maps that are not present in the standalone directory.
1. Create a Next.js project with output: 'standalone' in next.config.js. 2. Run `next build`. 3. Compare `.next/server/chunks` and `.next/standalone/.next/server/chunks` for `.js.map` files. 4. Observe that the original chunks directory contains .map files while the standalone directory contains zero.

Fixing Code Block

// scripts/copy-standalone-sourcemaps.js const fs = require('fs'); const path = require('path'); const srcDir = path.join(process.cwd(), '.next', 'server', 'chunks'); const destDir = path.join(process.cwd(), '.next', 'standalone', '.next', 'server', 'chunks'); function copyMaps(dir) { if (!fs.existsSync(dir)) return; for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { const fullSrc = path.join(dir, entry.name); if (entry.isDirectory()) { copyMaps(fullSrc); } else if (entry.name.endsWith('.js.map')) { const relative = path.relative(srcDir, fullSrc); const fullDest = path.join(destDir, relative); fs.mkdirSync(path.dirname(fullDest), { recursive: true }); fs.copyFileSync(fullSrc, fullDest); } } } copyMaps(srcDir); console.log('Copied source maps to standalone output.');
This postbuild script copies all .js.map files from the original build's server chunks into the standalone output. Add it to the package.json scripts: "postbuild": "node scripts/copy-standalone-sourcemaps.js". It ensures the sourceMappingURL references resolve correctly.

Edge Case Audit

Copying source maps into production can expose original source code if the maps contain sourcesContent. For security, only enable this when debugging or ensure the maps have sourcesContent stripped. Rollback: remove the postbuild script and delete the copied .map files from the standalone directory. If the upstream Next.js fix reverts the filter change, this script may become redundant but will not cause errors.

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