-
Notifications
You must be signed in to change notification settings - Fork 29.4k
Description
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:
-
Display line numbers in the original source code
-
Provide a mechanism for a developer to convert these webpack-internal line numbers to original source code line numbers
-
Pprovide a way to turn off the (?server-side ?webpack?) feature that contributes to this problem
-
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?