24sharon
24sharon

Reputation: 1975

Cannot debug nest js application in VSCode

I try to debug my nestjs application, I follow this article, https://javascript.plainenglish.io/debugging-nestjs-in-vscode-d474a088c63b but still cannot debug the application

This is my launch.json

   {
            "type": "node",
            "request": "launch",
            "name": "Debug Nest Framework",
            "args": [
                "${workspaceFolder}/api/src/main.ts"
            ],
            "runtimeArgs": [
                "--nolazy",
                "-r",
                "ts-node/register",
                "-r",
                "tsconfig-paths/register"
            ],
            "sourceMaps": true,
            "envFile": "${workspaceFolder}/.env",
            "cwd": "${workspaceRoot}/api",
            "console": "integratedTerminal",
            "protocol": "inspector"
        }

when I debugging the app seems start debugging but after get this error

return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
src/companies/companies.service.ts:13:49 - error TS2304: Cannot find name 'Company'.

enter image description here

How can I debug this app?

Upvotes: 1

Views: 5936

Answers (2)

Jason Huang
Jason Huang

Reputation: 216

No need to config luanch.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

Upvotes: 2

Jay McDoniel
Jay McDoniel

Reputation: 70131

Instead of setting up an entire debug script, you can make use of the one Nest sets up in new applications for you. start:debug maps to nest start --debug which starts your server (after building it if needed) and adds the --insert-brk flag for node to know you need the debug port available. Then you can use VSCode to attach to port 9229 and start debugging.

Upvotes: 1

Related Questions