question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 😃

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:34
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
kolpavcommented, Mar 7, 2021

@martaver Have you made any progress on this? It seems impossible to attach to client side js. Official docs ignore client side debugging entirely and most of the other resources assume you are going to use vscode to launch nextjs in repo containing just nextjs. Me using monorepo, typescript and docker-compose adds so many layers of complexity that after 3 hours of trying and then seeing you digging through PRs to find paths as "webpack://_N_E/*" I kind of gave up.

0reactions
balazsorban44commented, Jan 27, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript Programming with Visual Studio Code
Visual Studio Code includes built-in JavaScript IntelliSense, debugging, formatting, code navigation, refactorings, and many other advanced language ...
Read more >
Debugging in Visual Studio Code
The following documentation is based on the built-in Node.js debugger, but most of the concepts and features are applicable to other debuggers as...
Read more >
User and Workspace Settings - Visual Studio Code
The error can be as simple as a missing comma or incorrect setting value. Open the settings.json file with the Preferences: Open Settings...
Read more >
JavaScript Debugging Recipes for Visual Studio Code
In this article. Debug server-side JavaScript in Node.js; Debug client-side JavaScript in Browsers; Electron - Debug Electron applications; Next steps.
Read more >
Working with JavaScript in Visual Studio Code
More Actions dropdown), then type 'typescript'. Select the TypeScript and JavaScript Language Features extension and press the Disable button. VS Code built-in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found