javascriptnode.jstypescriptvisual-studio-codevscode-debugger

Visual Studio code breakpoint not working on Node.js using TypeScript


I have tried many solutions but not anyone works for me. The code executes, but I am not able to place breakpoints & debug it. Could you please help me?

I have tried the following VSCode configuration script:

{
      "type": "node",
      "request": "launch",
      "name": "Typescript Node JS",
      "program": "${workspaceFolder}/build/server",
      "preLaunchTask": "npm: build",
      "sourceMaps": true,
      "stopOnEntry": false,
      "internalConsoleOptions": "openOnSessionStart",
      "outFiles": [
          "${workspaceFolder}/out/**/*.js"
      ]
    },
    {
      "name": "ts node",
      "type": "node",
      "request": "launch",
      "args": [
        "${workspaceFolder}/server"
      ],
      "runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
      "sourceMaps": true,
      "cwd": "${workspaceRoot}",
      "protocol": "inspector"
    }

Solution

    1. Add the start script to package.json

      "scripts": { "start": "node ./node_modules/.bin/ts-node -- ./server.ts" }

    2. click on the debug menu icon on the left side navigation menu.

    3. Now click on show all automatic debug configurations.

    4. Now click on Node.Js(preview)

    5. Now all the scripts you have on package.json will be popped up. choose the start script.

    6. All Done!! Now breakpoints will work as expected :)

    Note: Please make sure you have the latest version of VSC, in the older versions it will not work.