Skip to content

Failed to connect to websocket. #29915

Closed
Closed
@UmbrellaCrow612

Description

@UmbrellaCrow612

Which @angular/* package(s) are the source of the bug?

compiler-cli

Is this a regression?

Yes

Description

When running angular over HTPPS following documentation available for example in my angular.json i added these options then ran my app through ng serve

   "serve": {
          "options": {
            "ssl": true,
            "sslKey": "ssl/private.key",
            "sslCert": "ssl/certificate.crt",
            "port": 4200,
            "host": "localhost",
            "hmr": true,
            "liveReload": true
          },

It runs on https://localhost:4200/ which is what i wanted but hmr failed with error

Image

And Hot module reload dose not work. There is a fix on Vite docs following link but there isn't a way for me to use that fix in the angular project as the Vite config is hidden from me ?

What can i do to fix this issue if i cannot change the Vite config ?

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

client:529 WebSocket connection to 'wss://localhost:4200/' failed: 
setupWebSocket @ client:529
(anonymous) @ client:524
app.config.ts:27 
            
            
           GET https://localhost:7058/users/me 400 (Bad Request)
scheduleTask @ zone.js:2183
scheduleTask @ zone.js:388
onScheduleTask @ core.mjs:6158
scheduleTask @ zone.js:382
onScheduleTask @ zone.js:271
scheduleTask @ zone.js:382
scheduleTask @ zone.js:205
scheduleMacroTask @ zone.js:228
scheduleMacroTaskWithCurrentZone @ zone.js:691
(anonymous) @ zone.js:2222
proto.<computed> @ zone.js:1003
(anonymous) @ http.mjs:2464
Observable2._trySubscribe @ Observable.js:33
(anonymous) @ Observable.js:27
errorContext @ errorContext.js:23
Observable2.subscribe @ Observable.js:23
(anonymous) @ switchMap.js:16
OperatorSubscriber2._this._next @ OperatorSubscriber.js:14
Subscriber2.next @ Subscriber.js:32
(anonymous) @ innerFrom.js:51
Observable2._trySubscribe @ Observable.js:33
(anonymous) @ Observable.js:27
errorContext @ errorContext.js:23
Observable2.subscribe @ Observable.js:23
(anonymous) @ switchMap.js:12
(anonymous) @ lift.js:10
(anonymous) @ Observable.js:27
errorContext @ errorContext.js:23
Observable2.subscribe @ Observable.js:23
(anonymous) @ catchError.js:9
(anonymous) @ lift.js:10
(anonymous) @ Observable.js:27
errorContext @ errorContext.js:23
Observable2.subscribe @ Observable.js:23
(anonymous) @ finalize.js:5
(anonymous) @ lift.js:10
(anonymous) @ Observable.js:27
errorContext @ errorContext.js:23
Observable2.subscribe @ Observable.js:23
doInnerSub @ mergeInternals.js:21
outerNext @ mergeInternals.js:15
OperatorSubscriber2._this._next @ OperatorSubscriber.js:14
Subscriber2.next @ Subscriber.js:32
(anonymous) @ innerFrom.js:51
Observable2._trySubscribe @ Observable.js:33
(anonymous) @ Observable.js:27
errorContext @ errorContext.js:23
Observable2.subscribe @ Observable.js:23
mergeInternals @ mergeInternals.js:54
(anonymous) @ mergeMap.js:20
(anonymous) @ lift.js:10
(anonymous) @ Observable.js:27
errorContext @ errorContext.js:23
Observable2.subscribe @ Observable.js:23
(anonymous) @ filter.js:6
(anonymous) @ lift.js:10
(anonymous) @ Observable.js:27
errorContext @ errorContext.js:23
Observable2.subscribe @ Observable.js:23
(anonymous) @ map.js:6
(anonymous) @ lift.js:10
(anonymous) @ Observable.js:27
errorContext @ errorContext.js:23
Observable2.subscribe @ Observable.js:23
(anonymous) @ tap.js:15
(anonymous) @ lift.js:10
(anonymous) @ Observable.js:27
errorContext @ errorContext.js:23
Observable2.subscribe @ Observable.js:23
(anonymous) @ catchError.js:9
(anonymous) @ lift.js:10
(anonymous) @ Observable.js:27
errorContext @ errorContext.js:23
Observable2.subscribe @ Observable.js:23
(anonymous) @ firstValueFrom.js:20
ZoneAwarePromise @ zone.js:2702
firstValueFrom @ firstValueFrom.js:5
(anonymous) @ app.config.ts:27
runInInjectionContext @ core.mjs:2454
runInitializers @ core.mjs:22338
(anonymous) @ core.mjs:34699
_callAndReportToErrorHandler @ core.mjs:22488
(anonymous) @ core.mjs:34697
invoke @ zone.js:369
onInvoke @ core.mjs:6494
invoke @ zone.js:368
run @ zone.js:111
run @ core.mjs:6346
bootstrap @ core.mjs:34653
internalCreateApplication @ core.mjs:37492
bootstrapApplication @ platform-browser.mjs:1192
(anonymous) @ main.ts:5
client:529 WebSocket connection to 'wss://localhost:4200/' failed: 
setupWebSocket @ client:529
fallback @ client:502
(anonymous) @ client:545
client:505 [vite] failed to connect to websocket.
your current setup:
  (browser) localhost:4200/ <--[HTTP]--> localhost:4200/ (server)
  (browser) localhost:4200/ <--[WebSocket (failing)]--> localhost:4200/ (server)
Check out your Vite / network configuration and https://vite.dev/config/server-options.html#server-hmr .
(anonymous) @ client:505
(anonymous) @ client:545
invokeTask @ zone.js:402
runTask @ zone.js:159
invokeTask @ zone.js:483
invokeTask @ zone.js:1138
globalCallback @ zone.js:1169
globalZoneAwareCallback @ zone.js:1202

Please provide the environment you discovered this bug in (run ng version)

ng version 19.0.5

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs: investigationRequires some digging to determine if action is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions