JavaScriptServices icon indicating copy to clipboard operation
JavaScriptServices copied to clipboard

Error when using HMR with ASP.NET CORE 2.0

Open praneethw opened this issue 9 years ago • 25 comments

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,

hrm_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 });

praneethw avatar Aug 18 '17 11:08 praneethw

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.

ghost avatar Jan 19 '18 01:01 ghost

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 avatar Jan 19 '18 15:01 racjc

@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,

ghost avatar Jan 20 '18 03:01 ghost

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 ] },

racjc avatar Jan 20 '18 11:01 racjc

npm install angular-router-loader --save-dev

Dragon38 avatar Apr 17 '18 20:04 Dragon38