VS Code Node.js debugger immediately exits if nothing anywhere in the code "forces" the main event loop to be active

Viewed 787

I have an issue with VS Code Node.js built-in debugger: it exits immediately (without executing anything) unless i add some kind of delay (such as setTimeout) anywhere in the code.

The basic code being tested:

var x = 5;
console.log('test');

Debug console output:

/usr/bin/node /home/dev/Desktop/Test/test.js
Debugger listening on ws://127.0.0.1:46297/de11d65b-015a-45eb-9c0b-6a0501513777
For help see https://nodejs.org/en/docs/inspector
Process exited with code 0

Modified code:

var x = 5;
console.log('test')
setTimeout(function() {}, 1000);

Gives this debug console output:

/usr/bin/node /home/dev/Desktop/Test/test.js
Debugger listening on ws://127.0.0.1:43463/51555bf6-94f4-4fcc-a766-442e0adc6fb3
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
test
Waiting for the debugger to disconnect...
Process exited with code 0

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}/test.js"
        }
    ]
}

No breakpoints fire in either situation, unless i add them to some code inside the timeout callback. What's going on here? I've tried to close and reopen the workspace folder, tried re-creating the launch.json. I also tried to follow some VS Code Node.js debugging tutorials but everything looks to be in order. Launching the script using "node" from the terminal directly works as expected in both cases.

0 Answers
Related