-
Notifications
You must be signed in to change notification settings - Fork 27.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SourceMap] prepareStackTrace
patch minifies server stack trace
#74646
Comments
This is an unfortunate side-effect of how we ensure source-maps work in both terminal and attached debuggers. Once you log the actual error object instead of just the stack, sourcemapping works as intended: -console.log(new Error().stack)
+console.log(new Error())
function names are not mapped due to a Node.js bug that would result in incorrect names. We're waiting on https://github.com/tc39/ecma426/blob/main/proposals/scopes.md to fix this. Keep in mind that you should not run a production server with |
Thanks for the information! The main reason we use We could potentially mitigate this by retaining the original error object and attaching new information directly to it instead. That said, I’d like to understand whether fixing this side effect would be difficult. Not being able to access a raw NodeJS API in our custom servers is a limitation I want to remove. |
I'd need to know more about how your logger is implemented. Though if it creates new error objects and then stashes the stack somewhere else, debuggers will not be able to sourcemap it properly either.
It's not possible if you manually extract |
Got it. Here are the three potential options I’m considering:
|
Link to the code that reproduces this issue
https://github.com/troyt-42/nextjs-source-map
To Reproduce
https://github.com/troyt-42/nextjs-source-map
yarn build
NODE_OPTIONS=--enable-source-maps yarn start
localhost:3000
Current vs. Expected behavior
Current:
The manual log's stack trace is minified even we have the
page.js.map
file generatedExpected:
After commenting out this line:
next.js/packages/next/src/server/patch-error-inspect.ts
Line 373 in 8ffa6c7
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.
The text was updated successfully, but these errors were encountered: