Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fail: Microsoft.AspNetCore.SpaServices[0]

Asp.net core 2.1 +Angular 6 application. In my Start.cs file. we have

app.UseSpa(spa =>
        {
            // To learn more about options for serving an Angular SPA from ASP.NET Core,
            // see https://go.microsoft.com/fwlink/?linkid=864501

            spa.Options.SourcePath = "ClientApp";

            if (env.IsDevelopment())
            {
                spa.UseAngularCliServer(npmScript: "start");
            }
        });

In the morning, I run the asp.net core application from Visual Studio(click F5). I got webpack build stuck on build module. It build a scss file for a long time and hangs there. So the web page throws asp.net core middleware exception.

However in the afternoon, I got a different error. Which is Fail: Microsoft.AspNetCore.SpaServices[0].

However if I run npm start in command window, then run dotnet run in Visual Studio code. It is fine.

Tell me what to do?

like image 428
Bigeyes Avatar asked Oct 15 '22 14:10

Bigeyes


2 Answers

For ngcc lock file it is causing issue. Simply delete 'node_modules' folder in 'ClientApp' folder and re build the application.

like image 134
Meghnath Das Avatar answered Oct 19 '22 02:10

Meghnath Das


I had a similar error as above (Fail: Microsoft.AspNetCore.SpaServices[0]) but for dotnet CLI (version 3.0.100, Angular 8.0). I simply created an Angular project - no error generated during build but when I ran it got the above error. After 10 minutes of investigation found the following issue during running angular server on it own:

screenshot angular build error

This is because the path for the module HomeComponent was blank:

screenshot missing module path in app.module.ts

This code was autogenerated by dotnet tool so I am not sure why this was left out. The HomeComponent module is in Home folder. So adding the path solved the problem.

This may be useful for other newbies out there.

like image 21
wkkhondkar Avatar answered Oct 19 '22 02:10

wkkhondkar