node runs code but does not stop at breakpoints in vscode

Viewed 1009

I have simple test code in node.js which i run in vscode on windows 10.

I put a breakpoint on the first line of code.

let x = 'hello world'
console.log(x)

my launch.json configuations are as follows.

"version": "0.2.0",
"configurations": [


    // nodes
    {
        "type": "node",
        "request": "launch",
        "name": "node: Launch Program",
        "program": "${file}",
        "console": "integratedTerminal",
    },
    {
        "type": "node",
        "request": "launch",
        "name": "node: Launch Program (External Terminal)",
        "program": "${file}",
        "console": "externalTerminal"
    }
    ]

The code runs in the integrated terminal and also the external terminal, but does not stop at the breakpoint if i were to set one.

This is what i see in the integrated terminal:

C:\Users\Owner\Dropbox\programming\javascript> cd c:\Users\Owner\Dropbox\programming\javascript && cmd /C "set "NODE_OPTIONS=--require C:\Users\Owner\AppData\Local\Temp\vscode-js-debug-bootloader.js" && set "VSCODE_INSPECTOR_OPTIONS={"inspectorIpc":"\\\\.\\pipe\\node-cdp.24028-42.sock","deferredMode":false,"waitForDebugger":"","execPath":"C:\\Program Files\\nodejs\\node.exe","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"C:\\Users\\Owner\\AppData\\Local\\Temp\\node-debug-callback-101745418fdd2bc6"}" && "C:\Program Files\nodejs\node.exe" .\test.js "
Debugger listening on ws://127.0.0.1:52096/7c733fea-7053-4446-8901-4220611d16ad
For help see https://nodejs.org/en/docs/inspector
hello world

I have tried all kinds of configurations, but none seem to work. I must presume that i have not invoked the debugger. What i do know is that the debugger is invoked for python when doing similar.

How can i get the code to stop at the breakpoint please ?

1 Answers

No solution was provided, so this is the best solution to date.

On inspection the debugger does in fact start.

Running this sample code:

let x = 'hello world'

let SomeSize = 1000
for (let i = 0; i < SomeSize; i++) {

    console.log(x, i)
}

console.log('the end')

The output is as follows:

hello world 525
hello world 526
hello world 527
Debugger attached.
hello world 528
hello world 529
hello world 530

So it is seen that the debugger does in fact attach, but after approximately 500 lines of code have already run (in this particular case).

If the program was short, say 100 loops, the user might not get a chance to inspect if the code ran to the end because the breakpoint would simply have been passed by before the debugger attached itself.

A follow up question might be how to delay the debugger such that this lagging behaviour is prevented for which the answer might be here: https://nodejs.org/api/debugger.html

Alternatively, use setTimeout to delay the code giving the debugger a chance to start.

Edited: the solution was to upgrade to the latest version of node: node -v v15.4.0

Related