Vscode: cannot break any breakpoint with Visual Studio Code on startup with nodemon

VSCode Version: 1.10.2 OS Version: Windows 7 Profesionnal, SP1 Node Version: 6.10.0

Hello to all.

I am trying to debug server side typescript code (or javascript code) with visual studio code when run from nodemon. I added a new config to launch.json that looks like this:

{
      "type": "node",
      "request": "launch",
      "name": "Launch server with Nodemon",
      "runtimeExecutable": "nodemon",
      "runtimeArgs": [
        "--debug=5858"
      ],
      "program": "${workspaceRoot}/src/server.ts",
      "restart": true,
      "port": 5858,
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "outFiles": ["${workspaceRoot}/build/**/*.js"]
    }

      

I have a task in vscode that runs tsc that generates javascript files correctly. This is my current task configuration:

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "0.1.0",
  "command": "tsc",
  "isShellCommand": true,
  "args": ["-p", "."],
  "showOutput": "silent",
  "problemMatcher": "$tsc"
}

      

The javascript files are generated as expected when the typescript file changes. And the nodejs server restarts as expected when the javascript file is generated.

But I cannot break any breakpoint (in typescript files or javascript files).

Can you please tell me if this is a problem, or if there is something I am missing?

thanks for the help

+3


source to share


3 answers


Looks like the issue is in vscode (issue open on github [here] [1]). But for now, the workaround is to set the protocol in the config (launch.json) to "inspector". With this option, breakpoints will now be hit correctly.

Also change "- debug = 5858" in the "runtimeArgs" option to "- check = 5858"

{
  "type": "node",
  "request": "launch",
  "name": "Launch server with Nodemon",
  "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
  "runtimeArgs": [
    "--inspect=5858"
  ],
  "program": "${workspaceRoot}/src/server.ts",
  "restart": true,
  "port": 5858,
  "protocol": "inspector",
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen",
  "outFiles": ["${workspaceRoot}/build/**/*.js"],
  "sourceMaps": true
},

      

Also, after that, if you have a blinking message:

Unable to connect to execution process, timeout after 10000ms - (reason: unable to connect to target: connect to ECONNREFUSED 127.0.0.1:5858)

This means that your program is too short and that the debugger does not have enough time to break the breakpoint. To solve this problem, add a second runtime parameter to the "runtimeArgs" parameter: "- debug-brk" and set too "stopOnEntry" to true strong>



The final configuration should look like this:

{
  "type": "node",
  "request": "launch",
  "name": "Launch server with Nodemon",
  "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
  "runtimeArgs": [
    "--inspect=5858",
    "--debug-brk"
  ],
  "stopOnEntry": true,
  "program": "${workspaceRoot}/src/server.ts",
  "restart": true,
  "port": 5858,
  "protocol": "inspector",
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen",
  "outFiles": ["${workspaceRoot}/build/**/*.js"],
  "sourceMaps": true
}

      

It should break on the first line of your javascript file. Then you can hit F5 and it will hit your own breakpoint.

If you don't want to hit F5 every time you run your program, you can instead embed your main entry code in the setTimeOut function with a timeout of at least 1000ms.

All of these options will provide enough time for vscode to break your breakpoints.

: //github.com/Microsoft/vscode/issues/23900 "GitHub Issue"

+3


source


@ManfredSteiner

I also had this question. You were probably only trying to break at the beginning of your login file (main.ts). I heard that we have this error message because the program is too short and exits before the debugger can connect successfully. You have 2 solutions:

  • First, put your input code inside the setTimeOut function at least 1000ms. This should give the debugger enough time to attach to your program.

  • The second solution is to set your launch.json parameters: "stopOnEntry" to "true" and set the runtimeArgs parameter to ["--inspect = 5858", "--debug-brk"].



Like this: "configurations": [ { "type": "node", "request": "launch", "name": "nodemon", "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon", "runtimeArgs": [ "--inspect=5858", "--debug-brk" ], "stopOnEntry": true, "program": "${workspaceRoot}/src/server/main.ts", "restart": true, "port": 5858, "protocol": "inspector", "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "outFiles": ["${workspaceRoot}/dist/**/*.js"], "sourceMaps": true } ]

It will break on the first line of your main.js, and then by pressing F5 you can break your own breakpoint in main.ts. If you don't want to, every time you start your program, press F5 until it reaches a breakpoint. I suggest you use the first solution (put your main.ts entry code inside the setTimeOut function at least 1000ms). I hope this helps you.

+1


source


@Philoufelin thanks for your efforts. I tested them following your suggestions.

... added to tsconfig.json file

"outDir": "./dist"

      

snapshot from launch.json file

"configurations": [
   {  
     "type": "node",
     "request": "launch",
     "name": "nodemon",
     "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
     "runtimeArgs": [ "--inspect=5858" ],
     "program": "${workspaceRoot}/src/server/main.ts",
     "restart": true,
     "port": 5858,
     "protocol": "inspector",
     "console": "integratedTerminal",
     "internalConsoleOptions": "neverOpen",
     "outFiles": ["${workspaceRoot}/dist/**/*.js"],
     "sourceMaps": true
   }
 ]

      

But that won't work. After 10 seconds vscode will start flashing the message ...
Cannot connect to execution process, timeout after 10000ms - (Reason: unable to connect to target: connect to ECONNREFUSED 127.0.0.1:5858)

nodemon also prints the following line at the beginning:
chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:5858/a0f8f52a-47ec-4ddb-9f03-4eb1c97ef8aa

I tried this link in chrome, attachment works, but debugger instructions or breakpoints are ignored.

I noticed another difference from normal debugging with vscode. Normal debugging starts on the DEBUG CONSOLE tab. Nodemon starts in the TERMINAL tab.

0


source







All Articles