NestJS/VSCode Debugging not working in domain code

Viewed 613

I have an app that is written in NestJS that I have inherited. When I try to debug the app using nest start --debug I am having trouble hitting breakpoints.

The odd thing is, if I put a breakpoint in my main.ts file, it hits it just fine. It's once the project has loaded up all the controllers, modules and the like that I cannot hit the breakpoints in the various .ts files. If I load up one of the .js files from my dist folder, I can breakpoint them, but everytime I stop and restart, I have to delete the contents of my dist folder. If i don't I get a TS5055 error about not being able to overwrite files.

Here's the tsconfig.json I have:

{
    "compilerOptions": {
        "module": "commonjs",
        "declaration": true,
        "removeComments": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
            "watch": true,
        "allowJs": true,
            "allowSyntheticDefaultImports": true,
            "target": "es2017",
        "sourceMap": true,
        "outDir": "./dist",
        "baseUrl": "./",
        "incremental": false,
  },
  "exclude": ["apminsightdata", "devops", "node_modules"]
}

The apminsightdata is because of site24x7 integration and devops is where I keep documents and SQL for our other teams to run when deploying.

2 Answers

add this configuration in the launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch app",
            "type": "node",
            "request": "launch",
            "args": [
              "src/main.ts"
            ],
            "runtimeArgs": [
              "-r",
              "ts-node/register",
              "-r",
              "tsconfig-paths/register"
            ],
            "cwd": "${workspaceRoot}",
            "protocol": "inspector",
            "internalConsoleOptions": "openOnSessionStart",
            "env": {
              "NODE_ENV": "local",
              "NODE_PORT": "3000"
            },
            "sourceMaps": true,
            "console": "internalConsole",
            "outputCapture": "std"
          }
    ]
    
}

no need to config luangch.json

  1. Open Vscode, and enter CTRL+SHIFT+P, select Toggle auto attach, choose always
  2. Click the code line you want to debug
  3. npm run start

It will hit the line you want to debug

Related