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
0 -
Only
--inspect-brk
works at the moment.
https://github.com/nodejs/node/issues/309111 -
The same behaviour shows up when using NodeJS v12.18.4 LTS.
The--inspect-brk
option does not stop at the line withdebugger
statement but the first executing line. When continuing execution then it stops at the line with thedebugger
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#latestBest,
Zorawar0 -
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,
Tassos0 -
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
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?
0 -
@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).0 -
A possible workaround would be to use the setTimeout in the app.js instead of invoking directly the f method, something like
setTimeout(f, 5000)
And click on the chrome "inspect" link within 5 secs0 -
@giacomolm said:
A possible workaround would be to use the setTimeout in the app.js instead of invoking directly the f method, something likesetTimeout(f, 5000)
And click on the chrome "inspect" link within 5 secsThat would be a little less efficient because I don't want to wait that longer.
So I tend to use the debugger integrated in vscode when I am working on a project and want to debug some code.0 -
the course is being updated for Node 16 - the inspect-brk issue seems to be resolved in 16, use the --inspect-brk flag to pause at the first line of code.
1 -
Still the same problem on chapter 4...
Running the code with debugger keyword on line 2 and "node --inspect app.js" does not stop on line 2 as expected but throws the error.Windows 11, Node 16.14.0 via NVM
1 -
Yes,
--inspect-brk
still kinda works, but--inspect
still does not with Node 16. I say kinda because it initially stops at line 5(f()
) and once you click to resume, it then stops at thedebugger
line.Also just checked and it is also the case with Node.js v18.2.0
0 -
@schalkneethling stopping at line 5 makes sense. The debugger is stopping in the first tick before the first function call, that just happens to be on line 5. The code above it is a declaration, so it doesn't execute in the first tick.
0
Categories
- 10.1K All Categories
- 35 LFX Mentorship
- 88 LFX Mentorship: Linux Kernel
- 504 Linux Foundation Boot Camps
- 279 Cloud Engineer Boot Camp
- 103 Advanced Cloud Engineer Boot Camp
- 48 DevOps Engineer Boot Camp
- 41 Cloud Native Developer Boot Camp
- 2 Express Training Courses
- 2 Express Courses - Discussion Forum
- 1.7K Training Courses
- 17 LFC110 Class Forum
- 5 LFC131 Class Forum
- 19 LFD102 Class Forum
- 148 LFD103 Class Forum
- 12 LFD121 Class Forum
- 61 LFD201 Class Forum
- LFD210 Class Forum
- 1 LFD213 Class Forum - Discontinued
- 128 LFD232 Class Forum
- 23 LFD254 Class Forum
- 569 LFD259 Class Forum
- 100 LFD272 Class Forum
- 1 LFD272-JP クラス フォーラム
- 1 LFS145 Class Forum
- 23 LFS200 Class Forum
- 739 LFS201 Class Forum
- 1 LFS201-JP クラス フォーラム
- 1 LFS203 Class Forum
- 45 LFS207 Class Forum
- 298 LFS211 Class Forum
- 53 LFS216 Class Forum
- 46 LFS241 Class Forum
- 41 LFS242 Class Forum
- 37 LFS243 Class Forum
- 10 LFS244 Class Forum
- 27 LFS250 Class Forum
- 1 LFS250-JP クラス フォーラム
- 131 LFS253 Class Forum
- 995 LFS258 Class Forum
- 10 LFS258-JP クラス フォーラム
- 87 LFS260 Class Forum
- 126 LFS261 Class Forum
- 31 LFS262 Class Forum
- 79 LFS263 Class Forum
- 15 LFS264 Class Forum
- 10 LFS266 Class Forum
- 17 LFS267 Class Forum
- 17 LFS268 Class Forum
- 21 LFS269 Class Forum
- 200 LFS272 Class Forum
- 1 LFS272-JP クラス フォーラム
- 212 LFW211 Class Forum
- 153 LFW212 Class Forum
- 899 Hardware
- 217 Drivers
- 74 I/O Devices
- 44 Monitors
- 115 Multimedia
- 208 Networking
- 101 Printers & Scanners
- 85 Storage
- 749 Linux Distributions
- 88 Debian
- 64 Fedora
- 14 Linux Mint
- 13 Mageia
- 24 openSUSE
- 133 Red Hat Enterprise
- 33 Slackware
- 13 SUSE Enterprise
- 355 Ubuntu
- 473 Linux System Administration
- 38 Cloud Computing
- 69 Command Line/Scripting
- Github systems admin projects
- 94 Linux Security
- 77 Network Management
- 108 System Management
- 49 Web Management
- 63 Mobile Computing
- 22 Android
- 27 Development
- 1.2K New to Linux
- 1.1K Getting Started with Linux
- 528 Off Topic
- 127 Introductions
- 213 Small Talk
- 20 Study Material
- 794 Programming and Development
- 262 Kernel Development
- 498 Software Development
- 922 Software
- 257 Applications
- 182 Command Line
- 2 Compiling/Installing
- 76 Games
- 316 Installation
- 53 All In Program
- 53 All In Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)