When use another value instead of Development as ASPNETCORE_ENV..., not working HMR #317

Closed
opened 2025-08-09 17:15:49 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @jeffrey-igaw on 11/15/2017

a40adab38d/src/Microsoft.AspNetCore.NodeServices/Configuration/NodeServicesOptions.cs (L39-L45)

Context

When i develop in local, actually i used Local environment value as ASPNETCORE_ENVIRONMENT instead of Development

So i configure several codes in Startup.cs as below

if (env.IsDevelopment() || env.EnvironmentName == "Local")
{
    app.UseDeveloperExceptionPage();
    app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
    {
        HotModuleReplacement = true
    });
}

and change my system environment value ASPNETCORE_ENV... to Local
finally dotnet run and i checked [HMR] connected in chrome console.

Problem

when i edit my client component but HMR was not working with warning log need full reload

image

Just all ok when ASPNETCORE_ENVIRONMENT value was Development.

Solution

i checked this file NodeServicesOptions.cs in repository.
The code is setting NODE_ENV to development when environment value was Development

In my case or someones want to use another values instead Development.
So how do you add the following code in WebpackDevMiddleware.cs?

// In WebpackDevMiddleware.cs
if(options.HotModuleReplacement && !options.EnvironmentVariables.ContainsKey("NODE_ENV")) {
    optinos.EnvironmentVariables["NODE_ENV"] = "development";
}

I'm sorry I did not speak English well. 😂 😂

*Originally created by @jeffrey-igaw on 11/15/2017* https://github.com/aspnet/JavaScriptServices/blob/a40adab38dba34458b25ecc2b3884278a8b2394c/src/Microsoft.AspNetCore.NodeServices/Configuration/NodeServicesOptions.cs#L39-L45 ## Context When i develop in local, actually i used `Local` environment value as `ASPNETCORE_ENVIRONMENT` instead of `Development` So i configure several codes in `Startup.cs` as below ```cs if (env.IsDevelopment() || env.EnvironmentName == "Local") { app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true }); } ``` and change my system environment value `ASPNETCORE_ENV...` to `Local` finally `dotnet run` and i checked `[HMR] connected` in chrome console. ## Problem when i edit my client component but HMR was not working with warning log `need full reload` ![image](https://user-images.githubusercontent.com/30995427/32823266-d270a4ae-ca1f-11e7-9a86-9737419b4733.png) Just all ok when `ASPNETCORE_ENVIRONMENT` value was `Development`. ## Solution i checked this file `NodeServicesOptions.cs` in repository. The code is setting `NODE_ENV` to `development` when environment value was `Development` In my case or someones want to use another values instead `Development`. So how do you add the following code in `WebpackDevMiddleware.cs`? ```cs // In WebpackDevMiddleware.cs if(options.HotModuleReplacement && !options.EnvironmentVariables.ContainsKey("NODE_ENV")) { optinos.EnvironmentVariables["NODE_ENV"] = "development"; } ``` I'm sorry I did not speak English well. :joy: :joy:
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#317
No description provided.