I have the following code:
basic-stream.js:
const readStream = require('stream').Readable();
readStream.push('beep ');
I run it with node inspect basic-stream.js
, open my browser, open developer tools and click on the "Open dedicated DevTools for Node.js" button. This launches a new window for debugging my application.
I'm able to step through the code just fine. I can step into a function call and the debugger will go to the line where the function is, even if the function is a Node.js library.
I'm also able to put a breakpoint to somewhere in my code and when I click on "Resume script execution", the code will stop on the breakpoint.
However, when I try to insert a breakpoint in a Node.js library and then click on "Resume script execution", the breakpoint will not be hit, even though the execution will go through that point:
It doesn't work from the command line debugger either. I get "Could not resolve breakpoint - undefined" error when I try to set the breakpoint:
$ node inspect basic-stream.js
< Debugger listening on ws://127.0.0.1:9229/d694952c-7819-45d6-bdac-e0c1541553d7
< For help, see: https://nodejs.org/en/docs/inspector
< Debugger attached.
Break on start in basic-stream.js:1
> 1 const readStream = require('stream').Readable();
2 readStream.push('beep ');
3
debug> setBreakpoint(2)
1 const readStream = require('stream').Readable();
> 2 readStream.push('beep ');
3
debug> cont
break in basic-stream.js:2
1 const readStream = require('stream').Readable();
> 2 readStream.push('beep ');
3
debug> step
break in node:internal/streams/readable:218
216 // write() some more.
217 Readable.prototype.push = function(chunk, encoding) {
>218 return readableAddChunk(this, chunk, encoding, false);
219 };
220
debug> step
break in node:internal/streams/readable:227
225
226 function readableAddChunk(stream, chunk, encoding, addToFront) {
>227 debug('readableAddChunk', chunk);
228 const state = stream._readableState;
229
debug> list()
222 Readable.prototype.unshift = function(chunk, encoding) {
223 return readableAddChunk(this, chunk, encoding, true);
224 };
225
226 function readableAddChunk(stream, chunk, encoding, addToFront) {
>227 debug('readableAddChunk', chunk);
228 const state = stream._readableState;
229
230 let err;
231 if (!state.objectMode) {
232 if (typeof chunk === 'string') {
debug> setBreakpoint(230)
Uncaught Error: Could not resolve breakpoint - undefined
at _pending.<computed> (node:internal/deps/node-inspect/lib/internal/inspect_client:243:27)
at Client._handleChunk (node:internal/deps/node-inspect/lib/internal/inspect_client:213:11)
at Socket.emit (node:events:327:20)
at Socket.EventEmitter.emit (node:domain:486:12)
at addChunk (node:internal/streams/readable:304:12)
at readableAddChunk (node:internal/streams/readable:279:9)
at Socket.Readable.push (node:internal/streams/readable:218:10)
at TCP.onStreamRead (node:internal/stream_base_commons:192:23)
at TCP.callbackTrampoline (node:internal/async_hooks:129:14) {
code: -32000
}
debug>
What's the problem here? How can I fix this?