Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run React in Development mode with .NetCore in IIS?

I've used the Visual Studio template for .NetCore/React web app. By default, it runs in Development mode using IIS Express. However, if I set up a site in IIS, and a launch profile, I get an error in the browser:

AggregateException: One or more errors occurred. (One or more errors occurred. (The NPM script 'start' exited without indicating that the create-react-app server was listening for requests. The error output was: Error: EPERM: operation not permitted, mkdir 'C:\Windows\system32\config\systemprofile\AppData\Roaming\npm'

My launchSettings.json has the following for the IIS profile:

"IIS": {
      "commandName": "IIS",
      "launchBrowser": true,
      "launchUrl": "http://localhost",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }

From the error, it looks like it may be a permission issue that I need to have the IIS app pool running under, but I can't find any documentation that tells me anything about that.

What am I missing? Again, this is an otherwise unmodified project from the template. The Startup.cs is running React as would be expected with:

app.UseSpa(spa =>
{
   spa.Options.SourcePath = "ClientApp";

   if (env.IsDevelopment())
      { spa.UseReactDevelopmentServer(npmScript: "start"); }
});
like image 866
Random Avatar asked Sep 05 '25 02:09

Random


1 Answers

According to your description, I suggest you could firstly modify the IIS default application pool's identity to make sure it has the permission to run npm.

I suggest you could follow below steps:

1.Open the IIS management console, locate the application pool,find the default application pool and click the advanced setting.

enter image description here

  1. Find the identity setting and modify the build-in account to localsystem

enter image description here

Then I suggest you could add the npm path in the system environment.

  1. Go to Control Panel\System and Security\System and find advanced system settings

enter image description here

2.Click environment variable

enter image description here

3.Find the path inside the system variable and add the npm path as below:

C:\Users\{username}\AppData\Roaming\npm 

enter image description here

like image 137
Brando Zhang Avatar answered Sep 09 '25 02:09

Brando Zhang