3

I thought the reason the new VS Code debugger stopped on the 'use strict'; in my file was because of some weird deprecatory behaviour in new versions of Node, or else because my code had some weird error in it.

Then I realised that "break on first line" is a thing, and one that people want. Why on earth is this a thing? I know that my script has a first line, thank you very much. I'd have bigger problems if it didn't. So why does the debugger need to do this?

Aron
  • 8,696
  • 6
  • 33
  • 59

3 Answers3

7

In launch.json there is a property stopOnEntry which is set to true by default. If you don't want to Node Debugger to "break on first line" set this property to false.

utkarsh
  • 143
  • 4
  • 1
    I believe `launch.json` is specific to only VSCode: https://nodejs.org/en/docs/guides/debugging_getting_started/ It would be nice to know how to disable the "stop on entry" setting in the native node cli debugger.... – modulitos Mar 08 '17 at 10:41
  • 1
    in the new versions of node it's --inspect-brk to break on first line and --inspect to not break on first line – Damon Smith May 03 '19 at 01:14
7

Now a toggle for this exists:

--inspect vs --inspect-brk
Ben Bieler
  • 1,518
  • 1
  • 14
  • 22
6

The reason "break on first line" is a feature, is so that you can run your application, and have it stop on the first line before continuing.

This allows you to attach a debugger before Node has executed some of the code. This enables you to debug the very first lines of code, set more breakpoints, or step over the lines of code whenever you are ready.

This is actually a pretty common feature in a debugger, especially if you don't necessarily have a way to set breakpoints before you run the code.

Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171
  • 2
    Is there a way to toggle off this "break on first line" feature? Perhaps there is a config file somewhere? See my comment to utkarsh's answer below – modulitos Mar 08 '17 at 10:43