-
Notifications
You must be signed in to change notification settings - Fork 518
Error when using HMR with ASP.NET CORE 2.0 #1204
Comments
I am also experiencing this problem. What I have attempted to do is to add AspNetCore.Identity to the initial template application, so that I can use standard forms authentication with an Angular app. When I first installed the Angular template, it was all working perfectly with hot module replacement. After installing the Identity components, as per the Microsoft article "Introduction to Identity on ASP.NET Core" found here, the application is still all working, but the hot module replacement is failing, with the message: "EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection." I can only assume that it is somehow interfering with the __webpack_hmr path. Any idea how I can get this working? I have put my application up on bitbucket here. I have disabled the Authorize attribute for now (it made no difference to HMR, it fails either way.) (Note: If you want to get the Authorization working, after making sure the initial application runs, open up the package manager console and type Update-Database. To add a new account, go directly to the URL /Account/Register and add an email address and password. Then you should be able to uncomment the Authorize attribute in the HomeController and it will authorize. When you run the app, it will redirect to the login page and you can log in. It will then return to the Home Index page and will be authorized. ) |
Ok, I've taken a look at the Network tab, and the __webpack_hmr file is being requested but I believe it is falling back to the default route and not returning __webpack_hmr. I have attached an image of the network tab, showing the __weback_hmr request below. In the original generated code, it is requesting __webpack_hmr from the dist folder (http://localhost:53145/dist/__webpack_hmr), but after installing the identity components and setting https, it is trying to get it from the root folder (https://localhost:44396/__webpack_hmr.) Would anyone know where I configure this? |
I should add, when I go directly to /dist/__webpack_hmr on the initial angular template, it shows the following: but when I try to go to the same URL in the Identity version, it redirects to the home page. I suspect I need to handle the route separately. |
Yes that's what I've seen as well, I think the dotnet routing is taking over and trying to handle the request, returning text/html, so it's sending the actual webpack_hmr hot file. |
Main goal is to re-align a bit more with JavaScriptServices to ensure people coming from there, wanting to add additional features, have an easier time syncing with this repo. Adds back vendor builds, Adds back fast HMR (but waiting for aspnet/JavaScriptServices#1204) AoT faster Cleans up multiple tsconfigs etc etc...
In the original, out of the box angular template, I do see an Event Stream tab when I look at the __webpack_hmr file under Network and it is responding with a type "text/event-stream". In the Identity version, it is returning text/html but I think this is because it is being routed to the home page. It can't get to the real __webpack_hmr file at all. |
I have managed to get the application working properly with Identity and HMR by rebuilding the application again incrementally. So that's an Angular 4 app on AspNet Core 2.0 on Dot Net Framework 4.7 using HMR and including Identity. It is stripped right down, so it provides simple Login with an email address and password, and I have added a logout button to the navbar as well. The Home controller has an Authorize attribute. If you aren't authorised, you will be redirected to Account/Login to log in to the site. There you can register an account, or if you have already registered one, log in. If the database hasn't been created for you, open up a package manager console and run Update-Database. The only thing I haven't done is to validate the anti-forgery token on logging out. That's because the existing Anti Forgery token is Http only, so I can't actually get access to it in typescript on the client to be able to post back to the server. So for now, the ValidateAntiForgeryToken attribute is commented out in the Account controller Logout method. I still haven't figured out why the other version of the app is not working. My working example can be found on bitbucket [here].(https://bitbucket.org/tonywr7/genericangularwebapp) |
I solved this by adding an option
Has something to do with https I think, because in the |
Glad you got this tracked down! |
* WIP - Re-sync with JavaScriptServices Main goal is to re-align a bit more with JavaScriptServices to ensure people coming from there, wanting to add additional features, have an easier time syncing with this repo. Adds back vendor builds, Adds back fast HMR (but waiting for aspnet/JavaScriptServices#1204) AoT faster Cleans up multiple tsconfigs etc etc... * fix gitignore * fix HMR, VS builds, misc updates * add package-lock to gitignore closes #307 closes #318 closes #296 closes #294 closes #271 closes #267 closes #230 closes #161
@MaximBalaganskiy I'd looked everywhere for a solution to this issue and this code did the trick for me:
Great work! |
* WIP - Re-sync with JavaScriptServices Main goal is to re-align a bit more with JavaScriptServices to ensure people coming from there, wanting to add additional features, have an easier time syncing with this repo. Adds back vendor builds, Adds back fast HMR (but waiting for aspnet/JavaScriptServices#1204) AoT faster Cleans up multiple tsconfigs etc etc... * fix gitignore * fix HMR, VS builds, misc updates * add package-lock to gitignore closes #307 closes #318 closes #296 closes #294 closes #271 closes #267 closes #230 closes #161
A note for the people from future. I mean do not do my error:
but do this:
|
@SteveSandersonMS I commented out this for some reasons. how do I over come above issue now?
|
Uncomment it?
…On 13 Dec 2017 2:00 AM, "AlwaysAbhl001" ***@***.***> wrote:
I commented out this for some reasons. how do I over come this issue?
//app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
//{
// HotModuleReplacement = true
//});
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1204 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALoUd0b58W7iy3n1hbr6JBWHepgPF8UVks5s_pT-gaJpZM4O7aNU>
.
|
@tonywr71 What about in production? where it ignores this part. |
I'm not sure what you're asking. None of us are telepathic. What error are
you getting, and is it related to this issue?
…On 13 Dec 2017 3:13 PM, "AlwaysAbhl001" ***@***.***> wrote:
@tonywr71 <https://github.com/tonywr71> What about in production? where
it ignores this part.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1204 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALoUdwDZ6pxbxleZWQp_ZlnBOm2lVM7zks5s_073gaJpZM4O7aNU>
.
|
@AlwaysAbhl001 HMR in production? What for? |
I commented HMR for some reasons in past. Added cookie authentication where it post back to callback controller to collect the token return a view. In such case for next call if user is already identified then returning Index view. This is my scenario where I'm facing this issue. And I'm looking for answer where I need not to touch the |
Not sure how |
Hi, |
Hi, guys , I am using MPA (multiple SPA) which means one MVC view returns a SPA. The [EventSource's response has a MIME type ("text/html") that is not 'text/event-stream'. Aborting the connection.] issue still happens to me after trying the fix mentioned by @MaximBalaganskiy . Any help would be appreciated, |
Hi,
This is the full code working for me. |
Hi, @racjc , I still have the same issue. Did yours combine with @MaximBalaganskiy solution ? |
Hi, no. here is my hotmodule conf:
Did you set the publicPath in webpack.config.js file ? |
@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, |
npm install angular-router-loader --save-dev |
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 });
The text was updated successfully, but these errors were encountered: