vercel / vercel/next.js

[SourceMap] `prepareStackTrace` patch minifies server stack trace

Open
#74,646 7 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

linear: next Runtime
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/troyt-42/nextjs-source-map

To Reproduce
  1. Checkout https://github.com/troyt-42/nextjs-source-map
  2. Install dependencies
  3. Generate a production build: yarn build
  4. Start the server with source map enabled: NODE_OPTIONS=--enable-source-maps yarn start
  5. Access localhost:3000
Current vs. Expected behavior

Current:
The manual log's stack trace is minified even we have the page.js.map file generated

Where am I: Error: 
    at i (.../nextjs-source-map/.next/server/app/page.js:1:31591)
    at ek (.../nextjs-source-map/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:84:13368)
    at e (.../nextjs-source-map/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:84:17266)
    at e$ (.../nextjs-source-map/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:84:17728)
    at Array.toJSON (.../nextjs-source-map/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:84:14874)
    at stringify (<anonymous>)
    at eU (.../nextjs-source-map/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:84:26231)
    at eB (.../nextjs-source-map/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:84:26461)
    at eq (.../nextjs-source-map/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:84:27015)
    at AsyncLocalStorage.run (node:async_hooks:346:14)

Expected:
After commenting out this line: https://github.com/vercel/next.js/blob/8ffa6c74b1f3fe357ce25bb455a565c6327dbd1e/packages/next/src/server/patch-error-inspect.ts#L373, I can see the source-mapped stack trace

Where am I: Error
    at i (webpack://nextjs-source-map/src/app/page.tsx:4:30)
    at renderFunctionComponent (webpack://next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.js:1006:15)
    at renderElement (webpack://next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.js:1082:12)
    at renderModelDestructive (webpack://next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.js:1121:1)
    at Array.toJSON (webpack://next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.js:1156:40)
    at stringify (<anonymous>)
    at emitChunk (webpack://next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.js:1734:43)
    at retryTask (webpack://next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.js:1755:11)
    at eq (webpack://next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.js:1803:7)
    at AsyncLocalStorage.run (node:async_hooks:346:14)
Provide environment information
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0: Wed Jul 31 20:48:04 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_T6030
  Available memory (MB): 36864
  Available CPU cores: 12
Binaries:
  Node: 20.12.2
  npm: 10.8.1
  Yarn: 1.22.22
  pnpm: 9.15.3
Relevant Packages:
  next: 15.1.3
  eslint-config-next: 15.1.3
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.2
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Runtime

Which stage(s) are affected? (Select all that apply)

next start (local)

Additional context

After reviewing patch-error-inspect.ts, it seems intentional that prepareStackTrace prevents error.stack from being source-mapped. If this is the intended behavior, there may be an issue in the downstream code.

This behavior is causing maintenance challenges for Faire after upgrading to Next.js version 15.1.3. Having source-mapped stack traces is critical for efficient debugging, and the absence of this feature significantly hinders our ability to troubleshoot issues.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/next/src/server/patch-error-inspect.ts, especially the prepareStackTrace code around line 373, then reproduce the behavior using the linked nextjs-source-map project with yarn build and NODE_OPTIONS=--enable-source-maps yarn start. Done means determining why next start returns minified server stack traces despite page.js.map and preserving the expected source-mapped output without breaking the intended stack inspection behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs
Domain
backend, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.