1

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?

5
  • How do you import the Company class? Commented Mar 8, 2021 at 18:54
  • Company is interface interface Company { id: string; name: string; email: string; boardMembers?: { firstName: string; lastName: string }[]; } Commented Mar 8, 2021 at 18:58
  • AFIK you can launch the app with ./node_modules/.bin/nest start --exec "node --inspect-brk" and select Debug: attach to node process in your command pallet Commented Mar 8, 2021 at 19:02
  • 1
    @24sharon okay., but how is it imported? Also to add on to @micael's comment you could just use nest start --debug (start:debug in the package.json) and attach to that process Commented Mar 8, 2021 at 19:08
  • WOW nest start --debug just work for me.... Thanks Commented Mar 8, 2021 at 19:19

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

Breakpoints do not hit.
Breakpoints are said "unbound", still …

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.