Error when using HMR with ASP.NET CORE 2.0
I have upgraded my solution to ASP.NET CORE 2.0, from 1.0 which was already configured for HMR. However after the upgrade I get the following error,

I can ofcource get rid of the error by setting HotModuleReplacement to false, however is there a fix to this such that I can continue to use SPA services with HMR?
The code for enabling HMR in my app is listed below,
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions() {
HotModuleReplacement = true
});
Hi, @racjc , I still have the same issue. Did yours combine with @MaximBalaganskiy solution ? Should this path be the same for everyone HotModuleReplacementEndpoint = "/dist/__webpack_hmr" ? My browser is loading the static file from the wwwroot directory in my project codebase.
Hi, no. here is my hotmodule conf: if (env.IsDevelopment()) { app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true,
ConfigFile = "webpack.config.js",
});
}
else
{
app.UseExceptionHandler("/Home/Error");
}
Did you set the publicPath in webpack.config.js file ? I guess that __webpack_mr is not found and your system return a defined 404 not found error file which is "text/html" content.
@racjc , I just realized that the <base href="@(string.Format("{0}://{1}{2}", Context.Request.Scheme, Context.Request.Host, Context.Request.Path))"> in the_Layout.cshtml causing the "EventSource's response" issue. So when I changed to href="~/" then this EventSource's error is gone. But my multiple SPA will not work. So what do you set for your base tag in html for MPA then?
Thanks,
Hi, @AdrianNg, I just put the application path as you define it in IIS. For instance if your path is http://mydomain/application/view in the _Layout.cshtml you just have to put href="/application/" And in the startup.cs file you have to defines routes in the Configure method. Something like that: app.UseMvc(routes => { routes.MapRoute( name: "default", template: "Views/{controller=Home}/{action=Index}.html/{id?}"); routes.MapRoute( name: "api", template: "api/{controller}/{id?}"); routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "Home", action = "Index" }); }); As I use cshtml file in Angular component as template, i insert the ".html" in the route template so the correct link will be done. For instance : @Component({ selector: "import-initial", templateUrl: "/application/Views/Partial/importinitial.html", styles: [require("./importinitial.component.css")] }) And in my webpack.config.js: module: { rules: [ { test: /.ts$/, use: ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader']}, { test: /.html$/, use: 'html-loader?minimize=false' }, { test: /.css$/, use: ['to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize'] }, { test: /.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }, ...sharedModuleRules ] },
npm install angular-router-loader --save-dev