question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Visual Studio Code Auto Attach debugging not working with NestJS

See original GitHub issue

Bug Report

Reference: nestjs/nest#5590.

Current behavior

In a new nx project with nest preset, after setting a breakpoint somewhere and configuring Visual Studio Code’s Debug -> JavaScript -> Auto Attach Filter with several configurations, the application will not start and the breakpoint will not hit when running nx serve. It does not matter wether I enable or disable Debug -> JavaScript -> Use Preview.

Different values for the auto attach setting have the following results: always image

smart image

onlyWithFlag image

disabled image

Expected behavior

The application should start and breakpoints should break processing. This was working up until recently. I am not entirely sure, but I believe up until at least 1 month ago it was working fine.

Having a project with just NestJS does work with Visual Studio Code’s auto attach debugging.

Environment


Nest version: 7.4.4

 
For Tooling issues:
- Node version: 14.13.1
- Platform: Mac

Others:

    "@nrwl/cli": "10.3.1",
    "@nrwl/eslint-plugin-nx": "10.3.1",
    "@nrwl/jest": "10.3.1",
    "@nrwl/nest": "10.3.1",
    "@nrwl/node": "10.3.1",

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

3reactions
florianmrzcommented, Dec 15, 2020

I’m facing the same issue with @nrwl/node v11.0.2, however, I might’ve found some additional information.

It possibly has something to do with the inspect argument being passed down to the child process, see this StackOverflow question.

https://github.com/nrwl/nx/blob/075fe9446b16e4e5c8bba78e4cb85888e5e50fe9/packages/node/src/builders/execute/execute.impl.ts#L75-L77

Since the whole nx serve process was being debugged, setting the “inspect” option to false in workspace.json worked for me, as the spawned child process would still be able to break on any breakpoints:

# workspace.json        
"serve": {
  "builder": "@nrwl/node:execute",
  "options": {
    "buildTarget": "api:build",
    "inspect": false
  }
},

Afterwards, using both the JavaScript Debug Terminal as well as the Auto Attach Feature with the following patterns worked for me:

# VSCode Settings (JSON)
"debug.javascript.autoAttachFilter": "smart",
"debug.javascript.autoAttachSmartPattern": [
  "!**/{node_modules,npm-global,.yarn,.nvm}/**",
  "**/$KNOWN_TOOLS$/**",
  "'**/node_modules/@nrwl/node/**'"
],
1reaction
ethan-dengcommented, Jun 21, 2022

Just switch to “command prompt” to run the command will work. “powershell” won’t work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NestJs not working with VScode auto-attach - Stack Overflow
When auto-attach is enable and I run the npm run start:debug I'm receiving the following error: Cannot connect to runtime; make sure that ......
Read more >
Debugging NestJS in VSCode - In Plain English
A step-by-step guide on how to debug your NestJS application and Jest tests using VSCode.
Read more >
Nest.js Debugging with VS Code.
In your VS Code Preferences: Code -> Preferences -> Search for Auto Attach and enable this. Then, from terminal run: npm run start:debug....
Read more >
Debug Node.js Apps using Visual Studio Code
In smart Auto Attach mode, VS Code will try to attach to your code, and not attach to build tools you aren't interested...
Read more >
Debug Node.js within a container - Visual Studio Code
How to configure and troubleshoot debugging of Node.js apps running in a Docker container ... Example: Configuring the entry point for a Nest.js...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found