nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.9k stars 7.55k forks source link

Debugging The App #776

Closed avinash-wissen closed 6 years ago

avinash-wissen commented 6 years ago

How can I debug this app in VSCode

joseluisq commented 6 years ago

Here my launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Nest Debug",
      "protocol": "inspector",
      "sourceMaps": true,
      "stopOnEntry": true,
      "console": "internalConsole",
      "program": "${workspaceFolder}/src/main.ts",
      "preLaunchTask": "tsc: build - tsconfig.json",
      "outFiles": [
        "${workspaceFolder}/dist/**/*.js"
      ],
+      "runtimeExecutable": "${env:HOME}/.config/fnm/bin/node"
    }
  ]
}

Make sure that you have Node: v8.9.1, otherwise you can change the binary path via runtimeExecutable. Verify also if you have "sourceMap": true in your tsconfig.json

avinash-wissen commented 6 years ago

All the sudden it recognizes this launch settings

    // 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": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}\\src\\main.ts",
            "preLaunchTask": "tsc: build - tsconfig.json",
            "outFiles": [
                "${workspaceFolder}/dist/**/*.js"
            ]
        }
    ]
}
kamilmysliwiec commented 6 years ago

There are some guidelines: https://github.com/nestjs/typescript-starter/issues/37 as well. Besides, I'm gonna provide a basic example in the official docs someday.

RobertoSnap commented 5 years ago

I just had this issue, with the new settings from Nest. This is working perfectly for me.

{ "type": "node", "request": "attach", "name": "Attach WS", "port": 9229, "restart": true, "stopOnEntry": false, "protocol": "inspector" }

RobertoSnap commented 5 years ago

Also... if you dont want the debugger to break at first line. Remove -brk from the nodemon-debug.json like this: { "watch": ["src"], "ext": "ts", "ignore": ["src/**/*.spec.ts"], "exec": "node --inspect -r ts-node/register -r tsconfig-paths/register src/main.ts" }

atul221282 commented 5 years ago

I think it is broken again, I am using nest 5.8.0 version and created brand new app from that cli and VSCode debugger is not working

dieison-depra commented 5 years ago

Em dom, 10 de fev de 2019 03:28, Atul notifications@github.com escreveu:

I think it is broken again, I am using nest 5.8.0 version and created brand new app from that cli and VSCode debugger is not working

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nestjs/nest/issues/776#issuecomment-462105300, or mute the thread https://github.com/notifications/unsubscribe-auth/ABtrA1t2e4uoyXRZxTJIS0NlK0luo453ks5vL64QgaJpZM4UhWW7 .

atul221282 commented 5 years ago

Em dom, 10 de fev de 2019 03:28, Atul notifications@github.com escreveu: I think it is broken again, I am using nest 5.8.0 version and created brand new app from that cli and VSCode debugger is not working — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#776 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/ABtrA1t2e4uoyXRZxTJIS0NlK0luo453ks5vL64QgaJpZM4UhWW7 .

Can't understand what you said @dadepra

lake2 commented 5 years ago

I just had this issue, with the new settings from Nest. This is working perfectly for me.

{ "type": "node", "request": "attach", "name": "Attach WS", "port": 9229, "restart": true, "stopOnEntry": false, "protocol": "inspector" }

stopOnEntry seems not woring, Does it work for you?

apeano commented 5 years ago

I just had this issue, with the new settings from Nest. This is working perfectly for me.

{ "type": "node", "request": "attach", "name": "Attach WS", "port": 9229, "restart": true, "stopOnEntry": false, "protocol": "inspector" }

I've read every discussion about not working breakpoints in vscode for NEST, no one fix worked, but this! Thanks!

raykle commented 5 years ago

Also... if you dont want the debugger to break at first line. Remove -brk from the nodemon-debug.json like this: { "watch": ["src"], "ext": "ts", "ignore": ["src/**/*.spec.ts"], "exec": "node --inspect -r ts-node/register -r tsconfig-paths/register src/main.ts" }

Worked for me! 👍

I opened the Debug > Node: Auto Attach option in VSCode settings, when I run start:debug script, it will start the debug task automatically. It's very convenient.

ghiscoding commented 4 years ago

I just had this issue, with the new settings from Nest. This is working perfectly for me.

{ "type": "node", "request": "attach", "name": "Attach WS", "port": 9229, "restart": true, "stopOnEntry": false, "protocol": "inspector" }

Finally something that works, thank you so much.

Just to add up that if you combine this to the new CLI commands in 6.8.x, it is now as easy as to run nest start --debug --watch or modify your NPM scripts with "start:debug": "nest start --debug --watch", run the script and then use the Attach WS Debug on 9229 and it works... woohoo!

More info in this Trilon blog post by Kamil.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.