5

I have added the configuration in the launch.json file with the following details :

{
    "name": "Attach"
    "type": "node",
    // TCP/IP address. Default is "localhost".
    "address": "localhost",
    // Port to attach to.
    "port": 5858
}

Now I start my app with the following command : node --debug-brk ./bin/www

When i go to VSCode and select Attach in the debugging menu on the top and click on the play button. It attaches, but when i go to browser and open a page, it doesn't it the breakpoint or the handler function in my index.js file. Can you please help what could be going wrong?

1

3 Answers 3

5

There are two issues with breakpoints in node (and these issues are not specific to VSCode but you can see them in node-inspector as well):

  1. If you set breakpoints in your app's startup code and launch node with --debug (opposed to --debug-brk), node starts immediately and has executed your startup code before VSCode had a chance to register the breakpoints. So if you need to debug startup code use the --debug-brk flag because it allows VSCode to set breakpoints before node starts the application.

  2. Node does not parse source files completely on load but delays parsing of closures (callbacks etc.) until their code is first hit. As a consequence breakpoints set on callbacks are not always correctly registered by node, because it does not have parsed the code yet. This 'lazy' behaviour can be disabled by starting node with the --nolazy flag.

In the next version of VSCode (0.4.0) we try to address these problem as follows:

  1. VScode will always launch node with the --debug-brk flag but will hide the first stop and continue if the user did not specify "stopOnEntry: true". This will avoid problems with missed breakpoints in startup code.

  2. If breakpoints are set in code that has not been parsed by node, node will register them at the next possible position in parsed code. Since these "actual" positions are returned by node to the client, VSCode is able to show these positions. So the user will see that a breakpoint set in an unparsed callback "jumps" to a position further down and he will better understand why the debugger is not stopping at the location requested. In addition we added a "Reapply" button to the breakpoint view which makes it really easy to clear and set all breakpoints.

Sign up to request clarification or add additional context in comments.

Comments

3

Your breakpoints are probably set too early and are not registered by node. It should help if you set the breakpoints after you have attached.

We have improved this experience in VSCode and it should be available in 0.4.0

3 Comments

Worked this time. Thanks so much!!
I have 0.3.0, is 0.4.0 available somewhere? I'm having similar debug attaching issues.
@Isidor See my details below in my answer for what works and what does not.
3

Always clear your breakpoints and set them after you attach. I learned the hard way. This is certainly a bug.

I've been digging into this and here is what I have found so far for 0.3.0.

This does not work!

  1. In Code add a breakpoint to app.js or a route
  2. In terminal run node --debug src/server/app.js
  3. In Code attach the debugger

This works!

  1. In terminal run node --debug src/server/app.js
  2. In Code remove all breakpoints
  3. In Code add a breakpoint to app.js or a route
  4. In Code attach the debugger

This does not work, as --debug doesn't kick in unless its the arg after node and before the file

  1. In terminal run node src/server/app.js --debug
  2. In Code remove all breakpoints
  3. In Code add a breakpoint to app.js or a route
  4. In Code attach the debugger

This works, assuming you have a gulp process

  1. In terminal run gulp serve-dev --debug
  2. In Code remove all breakpoints
  3. In Code add a breakpoint to app.js or a route
  4. In Code attach the debugger

This does not work, sometimes

  1. In terminal run gulp serve-dev --debug
  2. In Code add a breakpoint to app.js or a route
  3. In Code attach the debugger

Why sometimes? The best I can tell is that that the breakpoints sometimes get funky. Sometimes they work fine, and other times I have to remove them and re-add them before attaching the debugger.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.