I cannot figure out how to setup debugging in VS Code so I can serve the app with node in WSL. I am using:
This works in that is launches a new browser window and the app is served, but I cannot set any break points. They all report Unverified breakpoint
.
This is my launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"name": "React",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}/src"
}
]
}
The problem seems related to webpack, but I can't figure out what I need to do differently.
Visual Studio's WSL 2 toolset allows you to use Visual Studio to build and debug C++ code on WSL 2 distros without adding a SSH connection. You can already build and debug C++ code on WSL 1 distros using the native WSL 1 toolset introduced in Visual Studio 2019 version 16.1.
To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.
I have also struggled with this problem and found a solution:
My Setup
LOCAL => WSL
Use the following configuration in your launch.json
if you have started your vscode instance locally (not using WSL) and want to connect to a NPM instance running in WSL.
{
"name": "chrome-localhost-local-to-wsl",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}",
"sourceMapPathOverrides": {
"/mnt/c/*": "C:/*"
}
},
WSL => WSL
Use the following configuration in your launch.json
if you have started your vscode instance via WSL (using the Visual Studio Code Remote - WSL
extension) and want to connect to a NPM instance running in WSL.
{
"name": "chrome-localhost-wsl-to-wsl",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}",
"sourceMapPathOverrides": {
"/mnt/c/*": "/__vscode-remote-uri__/mnt/c/*",
},
}
You might have to adjust the drive in both configurations. I am running everything from C:/dev
so /mnt/c/*
is perfectly fine for me. If you have your code located for example at D:/dev/demo/src
you will have to use /mnt/d/*
.
What helped me a lot to debug what is going on was the .script command of the Debugger for Chrome
extension.
Update: It seems that something has changed recently in the integration of WSL, Chrome and VSCode so the sourceMapPathOverrides
are not required anymore. We successfully use the following configuration now for our WSL Setup:
{
"name": "chrome-localhost-wsl-to-wsl",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}",
}
You just need to add a sourceMapPathOverrides to your launch.json. It ends up looking something like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}",
"sourceMapPathOverrides": { "/mnt/c/*": "C:/*" }
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With