9

There have been a couple of older posts regarding this issue, but date from questions asked in 2013 and 2014 and the answers in there have not helped my case.

I have the debugger keyword placed in multiple places in my file, and have even added manual breakpoints in the inspector UI. Still, executing the file does not stop at any breakpoints. I am using node 9.2.0 and chrome 64.0.3282.167.

Here is a picture of how my devtools appears.enter image description here

Govind Rai
  • 14,406
  • 9
  • 72
  • 83

7 Answers7

8

Use the --inspect-brk flag instead

I ended up opening up an issue on the devtools protocol github page.

I got an immediate answer. Basically, because I was using the --inspect flag to start the Node.js debugger, my JavaScript was being executed before the debugger process was connecting to the DevTools server. Therefore breakpoint information would be relayed too late and no breakpoints would be triggered.

Example: node --inspect-brk myscript.js

They're currently trying to improve this use case. Here's the actual reply:

We are working on better workflow here but for now --inspect-brk is only one way. With --inspect-brk node waits DevTools frontend connection. On connection DevTools send all breakpoints information and starts JavaScript execution in node. With --inspect node starts JavaScript execution without waiting for DevTools frontend. As soon as DevTools connected, we send the same breakpoint information to node but it can be too late since some JavaScript is already executed.

The Node.js docs are not very clear on this subtlety as of 4/6/2018. I will submit a PR on their repo to update the docs. BTW, if you are not aware, even without the V8 integration, the built-in debugger is very powerful. Explore all the possibilities of the debugging utility in the docs.

Govind Rai
  • 14,406
  • 9
  • 72
  • 83
  • 3
    Tried this but it's not working for me. I was using just `--inspect` before and only injecting `debugger;` into my code could I hit a breakpoint. Changing to `--inspect-brk` didn't fix it. – roskelld Jun 22 '18 at 03:32
  • I'm now experiencing failure of the --inspect-brk flag to pause execution, when previously it worked. I'm running node.js V8.11.3 LTS, and Chrome reports its version as follows: 68.0.3440.106 (Official Build) (64-bit) Execution of node scripts fails to halt on "debugger" statements AND manually set breakpoints. – David Edwards Aug 15 '18 at 16:19
  • 3
    This is not the correct answer. `--inspect-brk` will successfully pause the application at the application entry point, but does not solve the issue with breakpoints set elsewhere in the code via the GUI. – WoodyWoodsta Nov 13 '18 at 11:18
  • @WoodyWoodsta at the time I asked this question, node was not having issues with some versions not working correctly with the debugging client. This was a very recent issue and this question (which was asked in april) got bombarded in november. But the answer still holds. It seems like the node debugging issues are fixed as of now. This answer still provides _the_ key information on debugging node apps using the chrome inspector, which is to use the `inspect-brk` flag to ensure none of your break points are missed. – Govind Rai Dec 08 '18 at 20:20
  • 1
    @GovindRai Apologies. It appears the node debugger is rather... buggy at the moment :) – WoodyWoodsta Dec 09 '18 at 21:04
  • 1
    Thank you, @GovindRai. Using `--inspect-brk` solved my problem on node 11.13.0 – MajidJafari Apr 11 '19 at 07:03
8

This is a problem that has been extremely annoying to me since 10.13 went to LTS and I upgraded from 8 to 10.

I was unable to find anything about this issue until I saw this question here on stack overflow, that was the catalyst I needed to be able find more about the problem and discover the cause and the solution.

You can find out more here: https://github.com/nodejs/node/issues/23693

The Why: Basically it is because of a change to the debugger protocol in Node.

The Solution: Upgrade Chrome to 71 or later which supports the change in the protocol.

Much Better Solution: Install NIM: https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj then go to the NIM settings and change the selected DevTools version to the one from chrome-devtools-frontend.appspot.com ( see more about this option here: https://june07.com/blog/nim-custom-devtools-url/ )

Dan Willett
  • 945
  • 2
  • 10
  • 20
4

I have this issue too: Chrome Devtools Inspector not stopping at breakpoints.

My problematic software versions:

  • Chrome: Version 70.0.3538.77 (Official Build) (64-bit)
  • Node: v10.12.0

A workaround I found is to downgrade NodeJS to version 8.12.0 (the latest 8.x version). Node version 8.x works for me.

$ node -v
v8.12.0

I also tried Node version 10.13.0, 11.1.0, none of them works for me.

FYI: How to change Node version

Yuci
  • 27,235
  • 10
  • 114
  • 113
  • 1
    Thanks for workaround! I spend couple of hours figuring where is the problem. Actually found that the latest working version is 10.11.0. – Vitaljok Nov 09 '18 at 08:42
3

The deeper reason seems to be that the debugger maintains two separate databases where it stores the breakpoints. Opening a file from the Sources tab, and setting breakpoints in it, is a waste of time. Maybe node considers these suspicious or unconfirmed -- whatever. They are ignored. These breakpoints are stored "somewhere" but not in the place that an active debugging session finds them or respects them.

You need to first manage to break the active execution of the source file that you want to debug, and then set the breakpoints while in a running context. You will notice that all breakpoints that you had previously set via the Sources tab have disappeared, and you can set new breakpoints. Only those new breakpoints are "observed" by node at runtime.

So the workaround today (September 2019) is as follows:

  1. Pepper the source file you wish to debug with debugger; statements
  2. Start your project with inspect-brk to force the debugger to stop the program before its first line is executed
  3. Click the little blue arrow to continue execution normally; the debugger; statements should now break in the source file you are interested in.
  4. Once you are stopped, you can set breakpoints that will actually be observed, and saved, in the "correct database" (for the lack of a better term).
blitter
  • 347
  • 5
  • 21
2

I had the same issue today while working with 10.13.0. based on the comment from answer 4, I tested different versions with $ nodenv local <version> and I had the following results:

10.13.0 (not working)

10.12.0 (not working)

10.11.0 (working)

10.10.0 (working)

Assuming lower versions work.

If you're not familiar with nodenv, you can get it here https://github.com/nodenv/nodenv

egaxhaj
  • 31
  • 2
1

I found that if I manually type:

debugger;

where I want the breakpoint to occur in my code then this actually fixes this issue for me. e.g.

var counter=0;
while (true) {
for (i = 0; i < 5; i++) {
debugger; //enter this through Chrome Dev then press CTRL s to save
counter++;
}
}

I'm running the above via: node --inspect-brk=0.0.0.0:5000 test_debugger.js [The 0.0.0.0 is here due to this being on a remote server.]

CMP
  • 1,170
  • 12
  • 11
0

I had a similar problem and found an easy fix. Instead of using chrome devtools, try node-inspector, which does the same thing - https://github.com/node-inspector/node-inspector#quick-start

  1. Open node.js command prompt
  2. Install the node-inspector package npm install -g node-inspector
  3. node-debug <your-entry-point> replace <your-entry-point> with your 'main' file, usually app.js by default (remember to navigate to the full file location if not already there e.g. C:\Users..)
  4. Wait for new browser window with node-inspector to open
sharaz
  • 1