Skip to content

Incorrect / missing documentation for debugging client-side javascript in VS Code #16442

@martaver

Description

@martaver

Bug report

Describe the bug

As best as I can tell, the documentation at https://nextjs.org/docs/advanced-features/debugging only describes how to configure debugging for the node process in vscode. It doesn't provide any specific instructions on how to debug code that is run in browser, in chrome at the client side.

I think this is problematic because (speaking for myself) most of the debugging I want to do is client-side debugging. nextjs is mostly a black box to me, and I am blissfully unaware.

It does, however, offer instructions on how to use chrome devtools to remotely debug the nextjs process... which I find a little confusing and misleading. It seems to suggest that this will somehow allow you to debug client-side javascript by simply attaching to the node process. I think this should be clarified.

If you are assuming the user is on the latest version of vscode-js-debug (https://github.com/microsoft/vscode-js-debug) and are assuming the user is clicking on the ready - started server on http://localhost:3000 in a Javascript Debug Terminal, then this should also explicitly be explained. These are new features and not obvious.

I think the documentation should also point out a valid launch configuration for those who are using Debugger for Chrome and want to debug the client-side javascript only, also showing how to modify it when using /src or when the app is at a subpath from the ${workspaceFolder}.

In particular, the need to use a custom sourceMapPathOverrides should be mentioned, as of 9.5.2 (or possibly earlier) the following properties in the configuration in launch.json is necessary for client-side sourceMaps to be resolved and for breakpoints set in vscode to bind:

            "webRoot": "${workspaceFolder}/pathto/app",
            "sourceMapPathOverrides": {
                "webpack://_N_E/*": "${webRoot}/*"
            }

When clicking on links in a Javascript Debug Terminal, then these properties need to be set in VSCode's settings here:
image

I found all this out the hard way, chronicling my adventures here:
https://stackoverflow.com/questions/63523469/how-can-i-configure-chrome-debugging-in-vscode-for-nextjs-9-5-2

In summary:

  • make a distinction between client-side and server-side debugging instructions
  • when using the (latest) vscode-js-debug plugin:
    • point out the need to open a Javascript Debug Terminal and click on the served link
    • point out the need to set webRoot (if at a subpath) and sourceMapOverrides in VSCode settings
  • when using Debugger for Chrome
    • provide a valid example launch configuration
    • include the sourceMapOverride
    • point out the need to add webRoot if at a subpath

Hope my points are valid and I'm not missing something blatantly obvious with all of this :)

Metadata

Metadata

Assignees

Labels

good first issueEasy to fix issues, good for newcomers

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions