Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging - Nx to automatically setup debugging configuration in vsCode on newly generated application #5539

Closed
un33k opened this issue May 3, 2021 · 22 comments
Assignees

Comments

@un33k
Copy link

un33k commented May 3, 2021

Description

Debugging is a natural part of any development lifecycle, for both distributed, and/or mono repos, alike. Nx users may benefit tremendously should the app-level generators automatically insert the relevant debugging information into the .vscode/{tasks,launch}.json files.

Motivation

Creating an Angular, or a NestJS, or any other app is very easy within the Nx workspace, which is meant to streamline and speed up the development process. That is all good till there is a need to attach to an application and step through some complex code, and that is all to avoid excessive use of console.log(s).

At that point, one can assume, setting up the debugging information turns into a monumental task. This is true since Nx moves things around to accommodates all variety of apps so they co-exist.

The same, let's say Angular app in Nx will give users a very hard time, should they try to set up the debugging information. However, if that application was created through NgCli, the setup would be a simple copy & paste of some configuration, right from the vsCode website.

Suggested Implementation

It would be great to automatically populate the .vscode/launch.json as well as .vcode/tasks.json with the necessary information regarding a newly generated application. Nx console already runs in & supports vsCode and the .vscode directory already exists, so we just need to add those two files.

One recommendation would be to add both launch <app> and attach <app>, so users can either have the launcher to start the app, then attach to it, or simply attached to an already laughed application.

@FrozenPandaz FrozenPandaz added the scope: misc Misc issues label May 3, 2021
@FrozenPandaz
Copy link
Collaborator

@un33k That sounds like a good workflow indeed. Perhaps you could set this up in a workspace-generator and share it with us while we figure out the details.

Personally, I've set up some tasks that were parameterized meaning I didn't need to add more config for each new app.

@Cammisuli @sandikbarr any ideas here? Could Nx Console help?

@Cammisuli
Copy link
Member

Yes actually. I was looking into providing debugging configs for Nx through Nx Console 😉

@ciriousjoker
Copy link

In the meantime, does anyone have a working launch.json file for Angular where breakpoints are hit and chrome opens properly after nx serve is done?

@github-actions
Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Jun 14, 2022
@ciriousjoker
Copy link

Any updates?

@github-actions github-actions bot removed the stale label Jun 15, 2022
@PointSingularity
Copy link

In the meantime, does anyone have a working launch.json file for Angular where breakpoints are hit and chrome opens properly after nx serve is done?

@ciriousjoker Have you been able to do this successfully?
I am able to start chrome after nx serve finishes, but the breakpoints are unbound :\

@ciriousjoker
Copy link

ciriousjoker commented Jun 22, 2022

@PointSingularity

{ 
   "version": "0.2.0", 
   "configurations": [ 
     { 
       "name": "Debug", 
       "type": "pwa-chrome", 
       "request": "launch", 
       "preLaunchTask": "Serve Frontend", 
       "url": "http://localhost:4200/#", 
       "webRoot": "${workspaceFolder}", 
       "sourceMapPathOverrides": { 
         "webpack:/*": "${webRoot}/*", 
         "/./*": "${webRoot}/*", 
         "/src/*": "${webRoot}/src/*", 
         "/*": "*", 
         "/./~/*": "${workspaceFolder}/node_modules/*" 
       } 
     } 
   ] 
 }

tasks.json:

{ 
   "version": "2.0.0", 
   "tasks": [ 
     { 
       "label": "Serve Frontend", 
       "type": "npm", 
       "script": "start", 
       "isBackground": true, 
       "presentation": { 
         "focus": true, 
         "panel": "dedicated" 
       }, 
       "group": { 
         "kind": "build", 
         "isDefault": true 
       }, 
       "problemMatcher": { 
         "owner": "typescript", 
         "source": "ts", 
         "applyTo": "closedDocuments", 
         "fileLocation": ["relative", "${cwd}"], 
         "pattern": "$tsc", 
         "background": { 
           "activeOnStart": true, 
           "beginsPattern": { 
             "regexp": "(.*?)" 
           }, 
           "endsPattern": { 
             "regexp": "Compiled |Failed to compile.", 
           } 
         } 
       } 
     } 
   ] 
 }

@PointSingularity
Copy link

@ciriousjoker Thank you for the reply!

This does start the app and opens up chrome, but the debugger doesn't attach, and the breakpoints are still unbound :\

Maybe I need to adjust the "webRoot" and "sourceMapPathOverrides" properties?

Browser Sources tab looks like this:
image

@ciriousjoker
Copy link

@PointSingularity Can't help you sorry.. for me it works perfectly :/

@PointSingularity
Copy link

PointSingularity commented Jun 22, 2022

@PointSingularity Can't help you sorry.. for me it works perfectly :/

@ciriousjoker Hey your code actually works!

I was just trying different things, but it turns out that Node version was the problem.
I was on Node 18.4.0 and this doesn't work, but the moment I switched to Node 16 it works as intended 😄
Not sure what got changed between those 2 versions in regard to the debugger though.
Thanks again!

Edit: Made it work on node 18.4.0 by adding '--host=127.0.0.1' to the start script.

...
 "start": "nx serve frontend-app --host=127.0.0.1",
...

@jonathan-barner
Copy link

jonathan-barner commented Sep 8, 2022

I got debugging working with my node.js service as well, using this launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Debug myservice",
            "cwd": "${workspaceFolder}",
            "runtimeExecutable": "nx",
            "runtimeArgs": [
                "serve",
                "myservice",
                "--inspect"
            ],
            "skipFiles": [
                "<node_internals>/**",
                "${workspaceFolder}/node_modules/*"
            ],
            "outFiles": [
                "${workspaceFolder}/dist/**/*.js"
            ]
        }
        // repeat for each debuggable app
    ]
}

@github-actions
Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label May 17, 2023
@tonivj5
Copy link

tonivj5 commented May 17, 2023

Up

@github-actions github-actions bot removed the stale label May 18, 2023
@FranciscoKloganB
Copy link

FranciscoKloganB commented Jul 23, 2023

I upvote this. Joined the monorepo bandwagon, because of the possible benefits it brings regardidng code sharing, but so far I only hit dev-experience issues. Can't debug, sharing stuff isn't always straight forward... Starting to think that seperate mono repos is just easier and better, with some NPM packages here and there.

Being unable to debug applications, libs and tests out of the box is a massive pain for any developer and having to deep search google results in search of random solutions, which most of the times don't work due to evolving APIs and versions, is miserable.

@zackarydev
Copy link

Up :)

@MPFGlaser
Copy link

Up from me as well. :)

@arieller
Copy link

Any progress with this?

@AsmisAlan
Copy link

any progress ?

@surajkrishan
Copy link

any progress team ?

@FrozenPandaz
Copy link
Collaborator

@MaxKless is there something we can do with this in Nx Console? 👀

@MaxKless
Copy link
Collaborator

MaxKless commented Apr 3, 2024

Hey everyone :) I'm going to add an Nx Console feature to automatically run a target through the debug terminal which should already be good for many cases. See the tracked issue here nrwl/nx-console#938

You're talking about browser-based applications, though, which need a launch configuration as you describe above. That seems like the job for a generator and not something we should do on the Nx Console side imo.

Could you elaborate on the specific issues you're running into trying to use the standard launch configurations specified by the VSCode docs? It seems to me like a bundled Angular + Nx app (for example) with source maps should work just as an Angular CLI app?
I'd be grateful for more in-depth information for what problems this potential generator would solve for everyone.

@MaxKless
Copy link
Collaborator

Hey!
I'm closing this in favor of nrwl/nx-console#2095

I'll work on a solution inside Nx Console that should automatically generate source maps when debugging.

Ultimately, there are going to be situations where we can't automatically generate source maps for you and you'll have to configure your specific tooling to include source maps in a dev build/serve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests