Aspnetcore: Microsoft.AspNetCore.SpaServices broken in NodeJS version > v8.11.3

Created on 28 Jan 2019  路  3Comments  路  Source: dotnet/aspnetcore

Describe the bug

Microsoft.AspNetCore.SpaServices throw error "Failed to proxy the request" when running on NodeJS at a version greater than v8.11.3.

To Reproduce

Steps to reproduce the behavior:

  1. Have NodeJS v8.15.0 or greater installed
  2. Open VS2017
  3. Go to File > New > Project...
  4. Select 'ASP.NET Core Web Application' click OK
  5. On subsequent dialog window select '.NET Framework', 'ASP.NET Core 2.2', 'Angular', click OK
  6. Open the resulting Solution
  7. On the toolbar at the top, select the dropdown green arrow (debug) button and change selection to "
  8. Kismet console window opens and runs as expected but any attempts to connect to the hosted application will eventually timeout with this exception:
System.Net.Http.HttpRequestException: Failed to proxy the request to http://localhost:2331/, because the request to the proxy target failed. Check that the proxy target server is running and accepting requests to http://localhost:2331/.

The underlying exception message was 'An error occurred while sending the request.'.Check the InnerException for more details. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly.
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.Http.HttpClient.<FinishSendAsyncUnbuffered>d__59.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.SpaServices.Extensions.Proxy.SpaProxy.<PerformProxyRequest>d__4.MoveNext()
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.SpaServices.Extensions.Proxy.SpaProxy.<PerformProxyRequest>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.SpaProxyingExtensions.<>c__DisplayClass2_0.<<UseProxyToSpaDevelopmentServer>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.<Invoke>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
  1. Uninstall NodeJS v8.15.0, install NodeJS v8.11.3.
  2. Rebuild and F5 to run the application again, now it works fine.

Expected behavior

Application should work correctly with all versions of NodeJS up to v10 (Highest supported by Angular library as of v7)

Screenshots

What Kestrel console shows with NodeJS v8.15.0 installed when I try to open the app in a browser:
2019-01-28 12_53_13-ng_nodejsv8-15-0

What it looks like when I switch tao v8.11.3 and is working:
2019-01-28 12_53_13-ng_nodejsv8-11-4

Additional context

dotnet --info output:
dotnet.txt

Visual Studio 2017 = v15.9.6
npm = v5.6.0

area-mvc feature-spa

Most helpful comment

I have the same issue with ASP.NET Core 2.1 and UseReactDevelopmentServer

All 3 comments

Thanks for contacting us, @k-vekos.
Are you still facing this issue?

I have the same issue with ASP.NET Core 2.1 and UseReactDevelopmentServer

@mkArtakMSFT I'm no longer having this issue on Node v10.15.3

Was this page helpful?
0 / 5 - 0 ratings