13

I followed the official documentation: https://code.visualstudio.com/docs/nodejs/angular-tutorial#_debugging-angular

  • Created a new Angular app using ng new my-app.
  • Opened the app in VSCode.
  • Checked if the app runs: ng serve. All good.
  • Installed Debugger for Chrome
  • Added launch.json configuration as instructed
  • Pressed F5 to start debugging...

According to the documentation it must launch the app and hit my breakpoints. Instead, I get this:

enter image description here

I have no idea why this is not working. Please advise. Thanks.

Also, why do we need this extension?

Looks like the debug module is built-in now in VSCode, and does exactly the same:

enter image description here

but is not working either (here I disabled the extension and used built-in debugger):

enter image description here

0

6 Answers 6

9
  1. Delete any existing launch.json from .vscode folder in your workspace.
  2. Press F5 (in your vscode workspace) and choose 'Chrome'. Note launch.json getting created afresh.
  3. Start your angular app from a terminal: 'ng serve --port=8080'. Wait till it is up.
  4. Go back to your vscode workspace. Press F5 to launch chrome in debug mode. Your app should load in Chrome.
  5. Now you can set breakpoints in your source code within vscode. Interact with your app as you normally would. vscode should pause when your hit your breakpoints.
Sign up to request clarification or add additional context in comments.

3 Comments

I am trying exactly this, chrome launches (very slowly), but the breakpoint "sourceMap": true became empty circle (unbound). More diagnostics: I've checked, "sourceMap": true and I can see and debug all my .ts sources in Chrome F12 devtools...
I would highly advise backing up your current launch.json first
goooooooooooood
3

I used to have your problems. I would struggle to find a solution and then some time later again the same thing. Always some confusing error with debugging from VS Code.

I moved to debugging my angular applications directly from browser and I am always happy. Chrome and Firefox have never disappointed me during debug.

Just keep in mind that for some strange reason webpack put all files under . source folder

Here is a picture of the structure and how you can find your files to debug directly from Chrome

enter image description here

You can also move to console tab and execute every statement that you want.

Also moving your mouse on the code will give you the values that your variables hold during execution.

2 Comments

Thanks, Boug. Yes, something weird is going on with VSCode debug. I have had problems with VSCode debug for years. It worked at some point, but suddenly stops working without any changes to launch.json. Chrome debug, yes, but the whole point is to be able to debug in VSCode, like the docs state. At this moment I don't see why we need the extension if the debug feature is built-in. With it, I have to start the app manually by "ng serve", and only then start the debug, not sure how long this will last. The "attach" option never works. They change things too often, but don't update the docs.
For me both the attach and listen functions seem always to have issues. I have invested much time in solving each issue separately, done my debugging , then some weeks later it does not work. Or I clone again another project and again it does not work. Therefore I have just switched to Chrome and Firefox debug and from that day I always debug directly without any issue so far.
1

install

npm install --global @azure/static-web-apps-cli@latest

Set your launch.json to

{
linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "SWA: Run Angular",
            "request": "launch",
            "type": "pwa-chrome",
            "url": "http://localhost:4280",
            "preLaunchTask": "swa: start Angular",
            "webRoot": "${workspaceFolder}/",
            "timeout": 30000
        }
    ]
}

Now go debug it

Comments

1

Took me ages to find it, but Turning off Sandboxing on VS Code solved my debugging issues.

VS Code -> Settings -> (Search for Sandbox) Uncheck: Window > Experimental: Use Sandbox

Hope that helps

Comments

0

check appconfig

"remoteServiceBaseUrl":"https://localhost:44301", "appBaseUrl": "http://localhost:4200",

check that remoteServiceBaseUrl is for localhos

Comments

0

After I upgraded my Angular from 10 to 15 my debugger stopped working. Turned out to be the webroot in launch.json: All I had to do was change it from:

"webRoot": "${workspaceFolder}/projects/my-app"

to:

"webRoot": "${workspaceFolder}"

Comments

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.