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

Starting Angular with debugger fails #167353

Closed
rajinder-yadav opened this issue Nov 28, 2022 · 41 comments · Fixed by microsoft/vscode-js-debug#1475 or microsoft/vscode-js-debug#1621
Closed
Assignees
Labels
author-verification-requested Issues potentially verifiable by issue author bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues verified Verification succeeded
Milestone

Comments

@rajinder-yadav
Copy link

rajinder-yadav commented Nov 28, 2022

Type: Bug

I am unable to get the debugger to connect to angular in debug mode, using angular v15.
I am using opensuse TW with KDE desktop.

  1. Create a new angular app using, 'ng new demo'
  2. Create debugger configuration (launch chrome).
  3. Set a breakpoint in app.component.ts
  4. Press F5

In my case the breakpoint becomes disabled (hollow circle with grey outline). The browser opens up and take a long time to show anything. The messages below are dumped in the terminal and the web-page gets displayed with no breakpoint hit.

Could not read source map for http://localhost:4200/runtime.js: Unexpected 503 response from http://127.0.0.1:4200/runtime.js.map: connect ECONNREFUSED 127.0.0.1:4200
WARNING: Processing source-maps of http://localhost:4200/main.js took longer than 5823.064334 ms so we continued execution without waiting for all the breakpoints for the script to be set.Could not read source map for http://localhost:4200/main.js: Unexpected 503 response from http://127.0.0.1:4200/main.js.map: connect ECONNREFUSED 127.0.0.1:4200
WARNING: Processing source-maps of http://localhost:4200/polyfills.js took longer than 999.4050689999995 ms so we continued execution without waiting for all the breakpoints for the script to be set.WARNING: Processing source-maps of http://localhost:4200/styles.js took longer than 999.4050689999995 ms so we continued execution without waiting for all the breakpoints for the script to be set.
[webpack-dev-server] Server started: Hot Module Replacement disabled, Live Reloading enabled, Progress disabled, Overlay enabled.
WARNING: Processing source-maps of http://localhost:4200/vendor.js took longer than 999.4050689999995 ms so we continued execution without waiting for all the breakpoints for the script to be set.
Angular is running in development mode. Call enableProdMode() to enable production mode.
[webpack-dev-server] Disconnected!
[webpack-dev-server] Trying to reconnect...
Could not read source map for http://localhost:4200/polyfills.js: Unexpected 503 response from http://127.0.0.1:4200/polyfills.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/styles.js: Unexpected 503 response from http://127.0.0.1:4200/styles.js.map: connect ECONNREFUSED 127.0.0.1:4200
Could not read source map for http://localhost:4200/vendor.js: Unexpected 503 response from http://127.0.0.1:4200/vendor.js.map: connect ECONNREFUSED 127.0.0.1:4200

VS Code version: Code - Insiders 1.72.0-insider (835d39c, 2022-09-28T05:18:50.781Z)
OS version: Linux x64 6.0.8-1-default
Modes:
Sandboxed: Yes

System Info

Operating System: openSUSE Tumbleweed 20221126
KDE Plasma Version: 5.26.3
KDE Frameworks Version: 5.100.0
Qt Version: 5.15.7
Kernel Version: 6.0.8-1-default (64-bit)
Graphics Platform: X11
Processors: 24 × AMD Ryzen 9 5900X 12-Core Processor
Memory: 62.7 GiB of RAM
Graphics Processor: NVIDIA GeForce RTX 3080/PCIe/SSE2
Manufacturer: Micro-Star International Co., Ltd.
Product Name: MS-7A38
System Version: 8.0

Item Value
CPUs AMD Ryzen 9 5900X 12-Core Processor (24 x 3999)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 0, 0, 0
Memory (System) 62.72GB (54.74GB free)
Process Argv . --crash-reporter-id 210d9130-10f4-4cf9-ad76-187d60112fd6
Screen Reader no
VM 0%
DESKTOP_SESSION /usr/share/xsessions/plasma5
XDG_CURRENT_DESKTOP KDE
XDG_SESSION_DESKTOP KDE
XDG_SESSION_TYPE x11
Extensions (64)
Extension Author (truncated) Version
terraform 4op 0.2.5
vscode-base64 ada 0.1.0
vscode-tomcat ada 0.12.1
markdown-navigation Ala 1.0.3
Bookmarks ale 13.3.1
aws-toolkit-vscode ama 1.56.0
ng-template Ang 15.0.1
vscode-apollo apo 1.19.11
vscode-tailwindcss bra 0.9.1
dep car 0.1.0
npm-intellisense chr 1.4.3
path-intellisense chr 2.8.3
vscode-markdownlint Dav 0.48.1
vscode-eslint dba 2.2.6
java-decompiler dgi 0.0.3
java-debug DSn 0.0.2
EditorConfig Edi 0.16.4
prettier-vscode esb 9.9.0
java-properties ith 0.0.2
plantuml jeb 2.17.4
angular-file-changer joh 0.0.4
vscode-peacock joh 4.2.2
sort-typescript-imports mic 1.4.1
vscode-docker ms- 1.22.2
playwright ms- 1.0.1
cpptools ms- 1.12.4
live-server ms- 0.4.4
vscode-typescript-tslint-plugin ms- 1.3.4
angular2-inline nat 0.0.17
vetur oct 0.36.1
vscode-boot-dev-pack Piv 0.1.0
vscode-manifest-yaml Piv 1.40.0
vscode-spring-boot Piv 1.40.0
platformio-ide pla 2.5.5
java-ide-pack pve 1.2.1
vscode-thunder-client ran 2.0.2
fabric8-analytics red 0.3.6
java red 1.12.0
vscode-commons red 0.0.6
vscode-xml red 0.22.0
vscode-yaml red 1.10.1
vue-vscode-snippets sdr 3.1.1
markdown-preview-enhanced shd 0.6.5
vscode-checkstyle she 1.4.1
java-generate-setters-getters soh 7.4.0
sonarlint-vscode Son 3.12.0
sass-indented syl 1.8.22
serverless-ide-vscode Thr 0.5.34
find-then-jump tra 2.0.5
sort-lines Tyr 1.9.1
intellicode-api-usage-examples Vis 0.2.6
vscodeintellicode Vis 1.2.29
vscode-java-debug vsc 0.46.0
vscode-java-dependency vsc 0.21.1
vscode-java-pack vsc 0.25.6
vscode-java-test vsc 0.37.1
vscode-lombok vsc 1.1.0
vscode-maven vsc 0.39.2
vscode-spring-boot-dashboard vsc 0.8.0
vscode-spring-initializr vsc 0.11.1
vscode-jumpy wma 0.3.1
better-align wwm 1.1.6
markdown-pdf yza 1.4.4
vscode-aspell zap 0.1.4

(8 theme extensions excluded)

A/B Experiments
vsliv695:30137379
vsins829:30139715
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30422396
pythontb:30258533
vsc_aa:30263845
pythonptprofiler:30281269
vshan820:30294714
pythondataviewer:30285072
vscod805cf:30301675
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30404738
cppdebug:30492333
vsclangdf:30492506
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30618038
pylantcb52:30590116
pyindex848:30611229
nodejswelcome1:30587009
pyind779:30611226
dbltrim-noruby:30604474

@ringodotnl
Copy link

ringodotnl commented Nov 29, 2022

Same issue on windows 10.
@rajinder-yadav: a work-around is to serve with a host defined like: ng serve --host=127.0.0.1

@molyviatis
Copy link

I have the same issue in VS2022

@rajinder-yadav
Copy link
Author

rajinder-yadav commented Dec 1, 2022

@ringodotnl Thanks for the work-around, got the debugger working!

  "scripts": {
    "ng": "ng",
    "start": "ng serve --host=127.0.0.1",

@rajinder-yadav
Copy link
Author

rajinder-yadav commented Dec 1, 2022

Another bug I noticed, if I stop my debug session using @ringodotnl work-around. Chrome shuts down, but ng serve keeps running in the terminal. As a result, I need to add the "Launch Chrome" configuration, switch to it and then press F5 to enter debug mode. The other option is, I stop 'ng serve' in the terminal or kill the terminal and press F5 without adding the "Launch Chrome" confguration.

I think this behariour is wrong and needs to be corrected.

Here is my launch.json

{
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Chrome",
      "request": "launch",
      "type": "chrome",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceFolder}"
    },
    {
      "name": "ng serve",
      "type": "pwa-chrome",
      "request": "launch",
      "preLaunchTask": "npm: start",
      "url": "http://localhost:4200/"
    },
    {
      "name": "ng test",
      "type": "chrome",
      "request": "launch",
      "preLaunchTask": "npm: test",
      "url": "http://localhost:9876/debug.html"
    }
  ]
}

@roblourens roblourens assigned connor4312 and unassigned roblourens Dec 5, 2022
@connor4312
Copy link
Member

I think this behariour is wrong and needs to be corrected.

Background tasks are made for this purpose: https://code.visualstudio.com/docs/editor/tasks#_background-watching-tasks

@connor4312 connor4312 added bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues labels Dec 5, 2022
@rajinder-yadav
Copy link
Author

Let me rephrase what I said. I should be able to press "F5" all the time and expect the same behaviour without any surprises to debug angular code.

@connor4312
Copy link
Member

connor4312 commented Dec 7, 2022

Thanks for the issue. Can someone who's experiencing this please provide the output of the following three commands?

curl -I http://127.0.0.1:4200/vendor.js.map
curl -I http://\[::1\]:4200/vendor.js.map
node -e 'dns.lookup("localhost", console.log)'

This is going to be based a bit on your local network, but I can reproduce this by explicitly telling ng serve to listen on ipv6 loopback while localhost resolves to ipv4 loopback. We do currently have a fallback that tries ipv4 assuming localhost might be ipv6, but not the other way around, and I suspect that might be what's happening here.

@connor4312 connor4312 added the info-needed Issue requires more information from poster label Dec 7, 2022
@rajinder-yadav
Copy link
Author

rajinder-yadav commented Dec 11, 2022

$ curl -I http://127.0.0.1:4200/vendor.js.map
curl: (7) Failed to connect to 127.0.0.1 port 4200 after 0 ms: Couldn't connect to server
$ curl -I http://\[::1\]:4200/vendor.js.map
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=utf-8
Accept-Ranges: bytes
Content-Length: 3025276
ETag: W/"2e297c-uigHuL6i7krMsHv4WkzAwCZEuEk"
Date: Sun, 11 Dec 2022 09:52:21 GMT
Connection: keep-alive
Keep-Alive: timeout=5
$ node -e 'dns.lookup("localhost", console.log)'
null ::1 6

@connor4312
Copy link
Member

Thanks. It looks like resolution is actually correct in your Node CLI environment. But maybe it does resolve to ipv4 localhost for VS Code, for whatever reason. I will attempt a fix.

connor4312 added a commit to microsoft/vscode-js-debug that referenced this issue Dec 12, 2022
@connor4312
Copy link
Member

Please try out the fix in the next nightly build, available when this comment is 7 hours old. Thanks!

@connor4312 connor4312 added this to the January 2023 milestone Dec 12, 2022
connor4312 added a commit to microsoft/vscode-js-debug that referenced this issue Dec 12, 2022
@rajinder-yadav
Copy link
Author

I don't think it's working? just to be sure, do I just create a fresh angular project and then press F5 to run the deugger? or do I still need to create a "Launch Chrome" configuration from the debug panel and then change the port to 4200 and run the debugger?

I've tried both with code-insider and it's still broken?

Version: 1.75.0-insider
Commit: 11238faea62d570d77afe6edfe05c8b732c44a2b
Date: 2022-12-13T05:22:26.937Z
Electron: 19.1.8
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Linux x64 6.0.10-1-default
Sandboxed: Yes

@rajinder-yadav
Copy link
Author

Here is a silent video of me showing the bug: https://www.youtube.com/watch?v=Fy5MLBHVd4s

There is also another bug with vscode, halfway through this video vscode get stuck going into debug mode and never gets there or opens the browser. You see me having to close vscode down and re-open it.

@connor4312
Copy link
Member

Insiders does not matter. You must be using the nightly debugger build using these instructions: https://github.com/microsoft/vscode-js-debug#nightly-extension

In the video it doesn't look like you're using that version of the debugger.

@rajinder-yadav
Copy link
Author

The new debugger looks really nice, however I followed the steps and still can't debug an angular application using the new extension.
I made another video with audio showing the problem.
https://www.youtube.com/watch?v=agscBrtHvHs

@rajinder-yadav
Copy link
Author

Also if I use the workaround to add the --host switch to the npm script, the new extension works when:

  1. I hit F5 with all terminals windows closed in vscode.
  2. Open the JS Debug Terminal, type npm start and then click on the link to open the browser.

However vscode insists on showing a greyed out breakpoint, but once the browser opens the breakpoint is hit and turns red. This is super confusing behaviour.

@rajinder-yadav
Copy link
Author

Another observation, when using the workaround:

From the basic terminal when I click on a link it will open the default browser which I have set to brave, but debugging will fail to work.

From the JS Debug Terminal clicking on a link will open Chrome browser and debugging seem to work, again using the workaround method.

@rajinder-yadav
Copy link
Author

Hello should I open a new bug as this one is closed?
I've also tested this on my MacOS, same problem exists and same workaround is required.

@Arash-Sabet
Copy link

@connor4312 This workaround worked.

@Arash-Sabet
Copy link

@connor4312 Any ETA on when this issue will be fixed to be able to run and debug angular apps as an SWA?

@Arash-Sabet
Copy link

@connor4312 This workaround worked.

The workaround stopped working with the recent release of SWA CLI 1.1.0. There is no option left to debug the app and everything has turned into a nightmare to proceed!

@connor4312 is there a way to fast-track an emergency release?

@charliemr99
Copy link

Same thing is happening to me. I'm blocked and can't debug Angular

@kondelik
Copy link

kondelik commented Mar 17, 2023

Debugging with SSL

I have to debug with SSL (Because reasons. Mainly OIDC provider refuse to return user with PKCE to http site). And I cant generate myself ssl cert with IP as DNS.

Symptoms:

Lots and lots of Could not read source map for https://localhost:4200/XXX.js: Unexpected 503 response from https://localhost:4200/XXX.js.map: connect ECONNREFUSED 127.0.0.1:4200

Breakpoints dont want to bind, even with "sourceMap": "true" etc.

Usage of ssl while debugging:

angular.json

"projects": {
  "my-cool-but-super-secret-project": {
    "architect": {
      "serve": {
        "options": {
            "ssl": true,
            "sslKey": "../../../../../../certs/domain/localhost.key",
            "sslCert": "../../../../../../certs/domain/localhost.crt",
            "host": "localhost"
        }
      }
    }
  }
}

And my curl:
curl https://localhost:4200/styles.js.map: OK
curl https://127.0.0.1:4200/styles.js.map: connection refused (this one is bcs i have "host": "localhost" in my angular.json)
curl 127.0.0.1:4200/styles.js.map: connection refused
curl http://127.0.0.1:4200/styles.js.map: connection refused
curl http://localhost:4200/styles.js.map: connection closed unexpectedly

My workaround for HTTPS / SSL / TLS:

Change "host" to "127.0.0.1" (same as previous workarounds)

angular.json

{
  "projects": {
    "my-cool-but-super-secret-project": {
      "architect": {
        "serve": {
          "options": {
              "ssl": true,
              "sslKey": "../../../../../../certs/domain/localhost.key",
              "sslCert": "../../../../../../certs/domain/localhost.crt",
              "host": "127.0.0.1"
          }
        }
      }
    }
  }
}

Now, when you try to curl https://127.0.0.1:4200/styles.js.map, connection is refused, because SSL cert is NOT valid for IP. Yeah, thats true, but we can work with that!

We can run node with environment variable NODE_TLS_REJECT_UNAUTHORIZED=0. I cant find any way to add env variables to angular.json (Not even sure if thats possible at all...), but it can be done:

AFAIK simplest solution is to use cross-env npm package:

npm install cross-env --save-dev
# OR
yarn add cross-env --dev

Then, I just add new script to "package.json":

{
 "scripts": {
    "start": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 ng serve",
    "test": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 ng test"
  },
  "devDependencies": {
    "cross-env": "^7.0.3"
  }
}

And I start my serve throught this script:

npm run start # Not sure if I wrote this correctly, I am using yarn :)
# OR
yarn start

And thats it. Breakpoints are bound, debugging work.

@Franiac
Copy link

Franiac commented Mar 18, 2023

Does microsoft/vscode-js-debug#1475 not have an error?

parsed.hostname = resolved.family === 6 ? '127.0.0.1' : '::1';

This does not look right... why did this get merged? No wonder, why this is still not working correctly, or am I overlooking something here?

@gkonstanzer
Copy link

Forcing the dev server to 127.0.0.1 works okey until then, but it's sad.

@Franiac
Copy link

Franiac commented Mar 24, 2023

Just to be clear, I misread that code and @rajinder-yadav (here) probably did, too.

parsed.hostname = resolved.family === 6 ? '127.0.0.1' : '::1';

This line in the PR is absolutely correct since it is the fallback code. It already has tried to send the request and failed. This code means "I have already tried IPv6 and now I need to try IPv4" or "I have tried IPv4 already and now I need to try IPv6". The code line on its own is misleading but makes sense in its context.

@Franiac
Copy link

Franiac commented Mar 24, 2023

Question is, if the PR got merged in January, when does hit the VSCode release?

@kondelik
Copy link

kondelik commented Mar 24, 2023

Why are they even trying to resolve the IP? Why not DNS/FQDN? It makes a problem with SSL because (self-signed) certs can't be on IP... 😩

@Franiac
Copy link

Franiac commented Mar 24, 2023

They ONLY do it for localhost.

const response = await this.requestHttp(url, options, cancellationToken);

if (response.statusCode === 503 && parsed.hostname === 'localhost') { // <-------------------- HERE
    let resolved: LookupAddress;
    try {
        resolved = await dns.lookup(parsed.hostname);
    } catch {
        return response;
    }

    parsed.hostname = resolved.family === 6 ? '127.0.0.1' : '::1';
    return this.requestHttp(parsed.toString(), options, cancellationToken);
}

connor4312 added a commit to microsoft/vscode-js-debug that referenced this issue Mar 29, 2023
TIL that assigning an invalid value to `url.hostname` silently fails
if invalid.

Fixes microsoft/vscode#167353
connor4312 added a commit to microsoft/vscode-js-debug that referenced this issue Mar 29, 2023
TIL that assigning an invalid value to `url.hostname` silently fails
if invalid.

Fixes microsoft/vscode#167353
@connor4312 connor4312 removed the info-needed Issue requires more information from poster label Mar 30, 2023
connor4312 added a commit to microsoft/vscode-js-debug that referenced this issue Mar 31, 2023
* fix: sourcemap lookups on ipv6 localhost addresses

TIL that assigning an invalid value to `url.hostname` silently fails
if invalid.

Fixes microsoft/vscode#167353

* fix: debugger failing on Node <=12

Fixes #1624

Updates @vscode/l10n to allow it to be tree-shaken away.

Also moves `checkContentHash` that likewise had a dependency on more
modern language features. I think webpack was just extra aggressive
about tree shaking before and assumed `new Hasher()` was side effect
free. Which is was, it's just a big assumption to have made.

And when I had updated versions in our pipelines, I accidentally updated
the minspec to no longer target Node 8 🤦‍♂️. Targeting the latest 10 should
be good. Node 8 thankfully <0.25% of users nowadays.

* keep broken minspec for the moment
connor4312 added a commit to microsoft/vscode-js-debug that referenced this issue Mar 31, 2023
* fix: sourcemap lookups on ipv6 localhost addresses

TIL that assigning an invalid value to `url.hostname` silently fails
if invalid.

Fixes microsoft/vscode#167353

* fix: debugger failing on Node <=12

Fixes #1624

Updates @vscode/l10n to allow it to be tree-shaken away.

Also moves `checkContentHash` that likewise had a dependency on more
modern language features. I think webpack was just extra aggressive
about tree shaking before and assumed `new Hasher()` was side effect
free. Which is was, it's just a big assumption to have made.

And when I had updated versions in our pipelines, I accidentally updated
the minspec to no longer target Node 8 🤦‍♂️. Targeting the latest 10 should
be good. Node 8 thankfully <0.25% of users nowadays.

* keep broken minspec for the moment
@pjunior94
Copy link

Same issue on windows 10. @rajinder-yadav: a work-around is to serve with a host defined like: ng serve --host=127.0.0.1

That fixed the issue for a brand-new application, but not for an application already using lazy-loading modules 😢

@rajinder-yadav
Copy link
Author

Same issue on windows 10. @rajinder-yadav: a work-around is to serve with a host defined like: ng serve --host=127.0.0.1

That fixed the issue for a brand-new application, but not for an application already using lazy-loading modules cry

well your module needs to be loaded for the break-point to be triggered, if you got the debugger working.

@roblourens roblourens added the author-verification-requested Issues potentially verifiable by issue author label Apr 27, 2023
@roblourens
Copy link
Member

@rajinder-yadav Can you confirm that your issue is resolved in the latest Insiders version of vscode?

@TylerLeonhardt TylerLeonhardt added the verified Verification succeeded label Apr 28, 2023
@rajinder-yadav
Copy link
Author

@roblourens it is working kind of, when I add the host entry ::1 to the host file.

$ ping localhost
PING localhost(ipv6-localhost (::1)) 56 data bytes
64 bytes from ipv6-localhost (::1): icmp_seq=1 ttl=64 time=0.024 ms

However when I refresh or hard-refresh sometimes the breakpoints don't get it, and sometime it will get it. Also I've noticed things run much slower now to the point I wouldn't want to use this debugger.

So to check, I commented out host entry ::1 in my hosts file and the debugger works all the time and it really responsive. When I do a refresh the breakpoint gets hit instantly.

$ ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.162 ms

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
author-verification-requested Issues potentially verifiable by issue author bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues verified Verification succeeded
Projects
None yet