Reputation: 1666
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?
Upvotes: 7
Views: 32238
Reputation: 12022
To get detailed information regarding to the problem causing this error, run the app via:
npm start
instead of dotnet run
.
Then if the error message indicates something e.g. missing packages, you may need to install the missing package(s) and after the problem is fixed you can continue to use dotnet run
command as before.
Upvotes: 1
Reputation: 155
For ngcc lock file it is causing issue. Simply delete 'node_modules' folder in 'ClientApp' folder and re build the application.
Upvotes: 2
Reputation: 186
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:
This is because the path for the module HomeComponent was blank:
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.
Upvotes: 2
Reputation: 1666
Find the answer by myself. It is still a bug of .NET-Core. Refreshing (F5) the page solved the problem and it works fine. (https://github.com/aspnet/JavaScriptServices/issues/1625)
Issues still exists, however just waiting it out and the angular builds, from my end the issue seems to be caused by the build order. What I mean is that the Server side code builds faster than the angular code, hence after waiting a second or two the error disappears.
Another way, if we run server first wait until webpack finish the compiling, then execute the command dotnet run
.
Upvotes: 0