help
                                
                                 help copied to clipboard
                                
                                    help copied to clipboard
                            
                            
                            
                        Breakpoint does not work on Node.js modules
- Node.js Version: v15.0.1
- OS: macOS
- Scope (install, code, runtime, meta, other?): code, debugging
- Module (and version) (if relevant): Stream but I don't think module is important
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:
What's the problem here? How can I fix this?
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> 
@nodejs/inspector Is this a bug?
That's not a bug afaik debugging inside core isn't supported.
The user can use the userland readable-stream (slightly older though) and break there https://www.npmjs.com/package/readable-stream :]
(Or they can build core from source and put a literal debugger that worked for me in the past (and there is --inspect-brk-node but I don't think that'd help)
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
Trying to pass the --no-node-snapshot argument to node. It may resolves the issue.
