Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to solve The NPM script 'start' exited without indicating that the Angular CLI

i am facing this error please help me this when i publish my app in IIS with angularjs please help me how to solve this error iam using .net core 2.1 and angularjs . In visual studio working fine I am facing this error in IIS

  services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
            });


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");
            }
        });

Error Screenshot: screenshot

like image 705
JOhns Avatar asked Dec 13 '22 14:12

JOhns


2 Answers

  • npm script 'start' means, .Net Core is trying to call ng serve to run the angular module in development env. So when your are hosting your application in Azure/local or any other server, make sure you have not deployed your application in Development environment. "ASPNETCORE_ENVIRONMENT": "Development" Change it to "ASPNETCORE_ENVIRONMENT": "Production". Refer here

  • After you have deployed in production mode and still facing any other errors. Try the following to find out the error. Comment out the following code block in Startup.cs

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

and deploy the application back in Development mode. You will get the real error message.

The variable can be changed in the ServiceManifest.xml file. By default it is not set.

like image 98
Mathew Abraham Avatar answered Dec 28 '22 11:12

Mathew Abraham


  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {

      app.UseDeveloperExceptionPage();
      app.UseHttpsRedirection();
      app.UseStaticFiles();
      app.UseAuthentication();
     app.UseSpaStaticFiles();    

      app.UseMvc(routes =>
            {
              routes.MapRoute(
                  name: "default",
                  template: "{controller}/{action=Index}/{id?}");

              routes.MapSpaFallbackRoute(
                    name: "spa-fallback",
                    defaults: new { controller = "Home", action = "Index" });
            });

      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");
        }
      });

    }

Add index.cshtml

like image 34
JOhns Avatar answered Dec 28 '22 11:12

JOhns