[FIXED] How can I debug typescript depending on where I set a breakpoint in a yarn workspace?

Issue

I have the following launch.json file since I am using ts-node:

{
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "runtimeArgs": ["-r", "ts-node/register"],
      "args": ["${workspaceFolder}/packages/first/src/index.ts"]
    }
  ]
}

Currently it is set to debug the index.ts inside the first project but what if I want to debug the second project assuming there is one with the same structure? I tried specifying a glob pattern like "${workspaceFolder}/packages/**/src/index.ts" but that did not seem to work, is there a way to achieve this without having to change the folder path everytime?

Solution

You want to debug multiple programs, so you should add multiple configurations. Nothing stops you from adding multiple configs in the launch.json, and naming them for each project. This let you select from VSCode which program you want to launch and debug easily.

{
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program: First",
      "runtimeArgs": ["-r", "ts-node/register"],
      "args": ["${workspaceFolder}/packages/first/src/index.ts"]
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program: Second",
      "runtimeArgs": ["-r", "ts-node/register"],
      "args": ["${workspaceFolder}/packages/second/src/index.ts"]
    }
  ]
}

Answered By – leonardfactory

Answer Checked By – Willingham (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published