node.jsvisual-studio-codevscode-debugger

Why won't VS Code debug my Hello World node.js program?


Just looking to join the VS Code crowd and stumbling out of the gate. I'm follow along with a tutorial at https://code.visualstudio.com/docs/nodejs/nodejs-tutorial.

The tutorial guides me to create a simple app.js

var msg = 'Hello World';
console.log(msg);

I can run this in the integrated terminal (running node app.js) and see the output there. Everything goes smoothly until I try to run it in debug mode with a breakpoint on line 1. I set the breakpoint fine, then run in debug (pressing F5). I'm asked which debugger to use and I select node.js. I then see, very briefly, the debug menu flash at the top of the editor area, the text C:\Program Files\nodejs\node.exe .\app.js show up in the debug console and the status line briefly flash blue.

On further attempts, I'm no longer asked to choose a debugger, but otherwise the result is the same. I never see any debug cursor nor any 'Hello World' output from my program. I also tried using a launcher to see if that would make a difference. Here's what it looks like:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}\\app.js"
        }
    ]
}

Unfortunately, this was no different.

This question gave me the idea to try adding "stopOnEntry": true to my launch configuration. Still no joy.

I also thought I might find a clue in the log files so I added "trace": true to launch.json and tried again. The debug console directed me to check for verbose logs written to {very long path}\vscode-debugadapter-1d4fecdb.json.gz. With the help of Microsoft's log analyzer, I combed through the trace and could see the debug adapter protocol (DAP) messages exchanged between VS Code and the Javascript debug adapter. I see the message requesting a breakpoint be set and I see a reply containing "success": true, which seems positive.

There's a lot of other stuff in there but nothing that looks like an error to my novice eyes.

Can anybody help me figure out why my Javascript debugging is not working?

About my setup -- Originally this question referred to VS Codium, but having tried this same tutorial on a fresh install of VS Code with the same result, I can confirm that this is a problem with VS Code or my use of it.

I'm running v23.3.0 of node.js. and 1.95.3 of VS Code. Both VS Code and node.js are on my path and my OS is Windows 11.


Solution

  • Don't use node.js v23.3.0 downgrade to v22.12.0 (LTS)

    Check https://github.com/microsoft/vscode/issues/235038 for more detail