Description
Originally posted by @Spakman in #40857 (comment)
Given this debugger.js
:
const hello = 123;
console.log("Expect this to be displayed directly in STDOUT.");
debugger;
console.log("About to exit:", hello);
Running NODE_INSPECT_RESUME_ON_START=1 node inspect debugger.js
correctly skips the first line, instead breaking on the debugger;
statement. I'd expect the first console.log
output to appear directly in STDOUT rather than after the debug shell's <
(since the debugger;
statement hasn't been executed yet). While I would find that behaviour cleaner, this isn't really the end of the world since if I'm wanting to step through code then I'm likely a bit less concerned about output correctness.
Here's the output from that command:
< Debugger listening on ws://127.0.0.1:9229/23c5ccc6-0db3-44bb-832d-66f09aa17b83
< For help, see: https://nodejs.org/en/docs/inspector
<
connecting to 127.0.0.1:9229 ... ok
< Debugger attached.
<
< Expect this to be displayed directly in STDOUT.
<
break in debugger.js:3
1 const hello = 123;
2 console.log("Expect this to be displayed directly in STDOUT.");
> 3 debugger;
4 console.log("About to exit:", hello);
5
debug> cont
< About to exit: 123
<
< Waiting for the debugger to disconnect...
<
debug> .exit
A bigger issue for me is that the debug shell is both brought up automatically without any debugger;
statements (causing what I'd consider in this case to be malformed output) and doesn't terminate without user input. With this no_debugger.js
, running NODE_INSPECT_RESUME_ON_START=1 node inspect no_debugger.js
gives this output:
const hello = 123;
console.log("Expect this to be displayed directly in STDOUT.");
console.log("About to exit:", hello);
Here's the output:
< Debugger listening on ws://127.0.0.1:9229/bf6c2802-dfe0-422c-a1a5-7676ee21101e
< For help, see: https://nodejs.org/en/docs/inspector
<
connecting to 127.0.0.1:9229 ... ok
< Debugger attached.
<
< Expect this to be displayed directly in STDOUT.
<
< About to exit: 123
<
< Waiting for the debugger to disconnect...
<
debug> .exit
In an ideal world, I'd expect running this no_debugger.js
script to behave exactly as if I hadn't passed the inspect
argument.
While it wouldn't solve any output issues, is there perhaps another environment variable that I'm missing to disconnect the debugger automatically when the script exits?