Welcome to the Linux Foundation Forum!

Lab 4.2 - Setting a Breakpoint Using a Code Keyword

Question: The labs-2 folder has an ​app.js​ file, edit the file so that when started in Inspect mode it willpause in the first line of the ​f​ function.

function f (n = 99) {
debugger
if (n === 0) throw Error()
f(n - 1)
}

f()

Problem: I have given the command 'node --inspect app.js'
My application is not stopping in line 2. Am i doing something wrong here.

Comments

  • I am having the same issue. Node version 12.19.0

  • lcyzhlcyzh Posts: 1

    Only --inspect-brk works at the moment.
    https://github.com/nodejs/node/issues/30911

  • zorawarzorawar Posts: 14
    edited October 2020

    The same behaviour shows up when using NodeJS v12.18.4 LTS.
    The --inspect-brk option does not stop at the line with debugger statement but the first executing line. When continuing execution then it stops at the line with the debugger statement.

    I mentioned this in the second part of my post from October 4th which was made visible today.
    https://forum.linuxfoundation.org/discussion/857623/why-do-the-dynamic-evaluation-and-debugging-examples-have-different-behaviour-on-node-v12-18-4-lts#latest

    Best,
    Zorawar

  • Hi @anilfred . I had the same issue. I found the solution by starting the debugger using the line "node inspect .\app.js" without the two dashes and afterwards just type in chrome --> chrome://inspect and it should stop in "debugger".

    Regards,
    Tassos

  • thanks for bringing this up everyone, it does indeed seem to be a bug in Node. I'm going to reach out to core team members and see what can be done to fix it, if it continues to stall I'll update the training to work around this

  • ghortatghortat Posts: 1

    I'm doing right now the Node.js Application Development (LFW211) training. So has the interface changed from --inspect to inspect as subcommand? Is there any updated training material?

  • @ghortat no it's not changed, node inspect is a command line interface, node --inspect initialises the devtools debugging protocol that can be connected to via chrome://inspect.

    The problem with the specific example is there is no time between executing the command with --inspect and the runtime hitting the debugger statement to actually connect to the inspector protocol. The debugger statement is ignored as usual, because when using --inspect if there's no debugger client connected, the runtime isn't in a debugging mode.

    So for given code example here, the only approach is to use --inspect-brk.

    Where --inspect is applicable is with something like an HTTP server. You can interact with the server normally, and then at some future point connect devtools to the exposed inspect interface and begin to debug it (this would also trigger any debugger statements).

Sign In or Register to comment.