Skip to content
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

console stack trace line numbers are incorrect or un-source-mapped #26711

Closed
jason-crawford-xio opened this issue Jun 29, 2021 · 3 comments · Fixed by #28520
Closed

console stack trace line numbers are incorrect or un-source-mapped #26711

jason-crawford-xio opened this issue Jun 29, 2021 · 3 comments · Fixed by #28520
Labels
bug Issue was opened via the bug report template.

Comments

@jason-crawford-xio
Copy link

What version of Next.js are you using?

10.x, 11.0

What version of Node.js are you using?

14.17

What browser are you using?

N/A

What operating system are you using?

Linux, MacOS

How are you deploying your application?

npm run dev

Describe the Bug

The terminal console shows stack traces with invalid / low-value line numbers. For example:

Error: line2
    at handler (webpack-internal:///./pages/api/hello.js:4:9)
    at apiResolver (/home/jasonnet/jack_work/nextjs-blog/node_modules/next/dist/next-server/server/api-utils.js:8:7)
    at process._tickCallback (internal/process/next_tick.js:68:7)

where the line number of the problem in pages/api/hello.js is not 4.

Expected Behavior

One of the following:

  1. Display line numbers in the original source code

  2. Provide a mechanism for a developer to convert these webpack-internal line numbers to original source code line numbers

  3. Pprovide a way to turn off the (?server-side ?webpack?) feature that contributes to this problem

  4. or provide enough education here that an noob outside developer could generate a pull request implementing one of these solutions.

To Reproduce

Start with the create-next-app tutorial code found here. Then modify that handler function ./pages/api/hello.js to throw an Error:

export default function handler(req, res) {
  throw new Error("line2");
  res.status(200).json({ text: 'Hello' })
}

Then run npm run dev

If one then visits http://localhost:3000/api/hello one sees something like:

Error: line2
    at handler (webpack-internal:///./pages/api/hello.js:4:9)
    at apiResolver (/home/jasonnet/jack_work/nextjs-blog/node_modules/next/dist/next-server/server/api-utils.js:8:7)
    at process._tickCallback (internal/process/next_tick.js:68:7)

As you can see the line number is listed as 4 rather than 2. If you try to reproduce this and see a correct value ("2"), then update the hello.js to include an import at the top, which should cause the stack trace line number to no longer match hello.js file even if it matched earlier.

What is the process to convert these webpack-internal line numbers to line numbers in the original source files? Is there a process to avoid these webpack-internal line numbers altogether?

@jason-crawford-xio jason-crawford-xio added the bug Issue was opened via the bug report template. label Jun 29, 2021
@jason-crawford-xio
Copy link
Author

@timneutkens I see the commit. Thanks for your effort on this. That is helpful.

For those of use wanting to see the actual stack trace instead of the pretty-printed line of source code, is there a new API available to us to determine the line number and file for each stack frame in the stack trace? Perhaps createOriginalStackFrame and the callers of that function?

@FINDarkside
Copy link

Is this already in production? I'm still having this issue in 12.0.2

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants