I have an existing SPA based on Asp .Net Core (I was using Yo generator-aspnetcore-spa to generate a template). It worked perfectly fine, but after migration to .NetCore 2.0 it started to throw the error:
EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection.
As I understood this problem affects only auto-refresh after updating any file (hot module replacement as far as I know). All other stuff is working fine.
So, the question is how to fix the error above?
I found the solution, mainly the problem is in .NetCore routing system, it is taking over and trying to handle the request, returning text/html, so it's sending the actual webpack_hmr hot file. To fix it you need to edit Configure method in the Startup.cs file.
Before:
// some code
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
HotModuleReplacement = true
});
//some code
After:
// some code
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
HotModuleReplacement = true,
HotModuleReplacementEndpoint = "/dist/__webpack_hmr"
});
// some code
The solution is taken from this thread on GitHub
export ASPNETCORE_ENVIRONMENT=development
to your ~/.bash_profile
or ~/.zshrc
file.
This link explains how to change the env in more depth.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With