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.

About debug NestJS in Nx using WebStorm

See original GitHub issue

Updated

This issue (for WebStorm) has been solved and explained below, and @Areen3 also gives a comment for VSCode

Prerequisites

  • I am running the latest version
  • I checked the documentation (nx.dev) and found no answer
  • I checked to make sure that this issue has not already been filed
  • I’m reporting the issue to the correct repository (not related to React, Angular or any dependency)

Expected Behavior

Sorry for not asking question on Stack Overflow because I think it might be a common issue and GitHub is a better place to share these information.

  • As mentioned in title, I’d like to migrate from Angular + NestJS to Nx but I cannot set up debug environment as I did in pure NestJS demo project.
    • I wonder if there could have some official tutorials about how to debug using common IDEs/editors like for VSCode or WebStorm (e.g., put on the https://nx.dev/)
      • Or maybe if I just miss one !?
  • Here’s how the original NestJS works as the screenshot below.
    • The debugger stop at the breakpoint when getting request in the *.controller.ts file as expected. nest-debug-works

Current Behavior

  • I’ve tried to use the same way to debug Nx-NestJS project, but I got 2 results as shown below.
    • I wonder if the only way to debug is using the compiled dist/api/main.js, or I can do it in the original *.controller.ts file?
    1. Using original *.controller.ts that failed due to import issue nx-debug-failed
    2. Using compiled dist/api/main.js that works but quite tricky nx-debug-mainjs

Thanks for your help 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11

github_iconTop GitHub Comments

5reactions
tommyc38commented, Aug 6, 2021

For anyone else wanting to know how to debug NestJs with WebStorm, here are a few tips:

When you run nx serve "nest-app-goes-here" you will see that WebStorm automatically creates a debugging server. Note which port these are listening on.

Screen Shot 2021-08-06 at 11 29 13 AM

Next, create a run configuration in WS and select Attach to Nodejs/Chrome and create a new configuration by adding the port number. Now add your breakpoints and click on one of the debuggin links above which will open the debugger window in WS. Now use a rest client to send a request to trigger a breakpoint and it should work as expected.

You can also edit your serve configuration in your angular.json file (it maybe called something else if you aren’t using angular) by adding `port: “port number goes here - 9229 is standard though”. Then change your WS run configuration to use this port and now anytime you serve the application, all you need to do is click on the debugger link to launch the debugger and it should work without needing to change the port number in your run configurations (Nx automatically assigns a random open port each time the app is initially launched).

2reactions
Areen3commented, Nov 15, 2020

I had similar problem but under VSCode You have right it is from node

problem was with working directory this is exlained in https://blog.logrocket.com/es-modules-in-node-today/ image

when I set properly working directory in VSCode using: image these errors desapear

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running and debugging Node.js | WebStorm Documentation
The WebStorm built-in debugger can automatically reconnect to running Node.js processes. This lets you debug Node.js applications that use the ...
Read more >
Debug Jest in a NRWL/nx project with webstorm
Open your NRWL/nx project in webstorm (we have to start with some common ground here…) · Make sure you have a lib or...
Read more >
How to debug a NestJS app in nrwl monorep
1). The NestJS app is started via ng serve api , where api is the name of my NestJS app. When I try...
Read more >
Debugging a NestJS Application - Yvonne Allen - Nx Conf 2021
In this talk, Yvonne will walk you through the process of debugging a NestJS application within Nx.___Yvonne Allen is an Angular GDE and...
Read more >
Nx Tutorial: Debug Nx with Node and VSCode - YouTube
Being able to properly debug a problem is key in software development. And even though we try hard to provide meaningful error messages...
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