Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"
    }
like image 773
user8576367 Avatar asked Jul 25 '26 06:07

user8576367


2 Answers

  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.

like image 86
user8576367 Avatar answered Jul 26 '26 20:07

user8576367


I checked all the solutions and none of them worked for my case. at last, I cleared the "outFiles" line and it worked!

just comment out these lines:

  "outFiles": [
      "${workspaceFolder}/out/**/*.js"
  ]
like image 29
faridfedora Avatar answered Jul 26 '26 19:07

faridfedora



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!