15
votes

Everytime I start my application I get this. I don't use SSL and I am connecting to localhost:4200.

WebSocket is closed before the connection is established

What would cause this?

enter image description here

4

4 Answers

2
votes

I am also getting this problem with asp.net core and Angular 7.2.0. As I just tested it doesn't exist with Angular 6.1.10

This happens when using in startup.cs:

app.UseSpa(spa => { spa.UseProxyToSpaDevelopmentServer("http://localhost:4200"); });

When my asp.net core is running on other port. Any ideas how to solve it? The only workaround is to add http interceptor in angular with base url for my asp.net web api, but the UseProxyToSpaDevelopmentServer was definitely easier way.

Even better workaround is to use proxy on angular side with proxy.conf.json https://angular.io/guide/build#proxying-to-a-backend-server

1
votes

I had this message as well and for me it seems like the cause was service scoping. I had a service in the Providers section of a component for auth / login that caused it to be scoped locally. From what I could see it happened after the post login navigation to another page. I removed it from the providers list and the error went away.

0
votes

You can fix this by adding TypeScriptCompileBlocked in your .csproj

<PropertyGroup>
  <TargetFramework>netcoreapp2.2</TargetFramework>
  <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>
0
votes

Not sure what causes this but I have observed that when ChangeDetectionStrategy imported from '@angular/core' in the component, the warning goes away.

Please confirm if same happens for you also.