6

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

4
  • Angular 1.x? Or angular 2 and above? Commented Oct 10, 2018 at 3:45
  • angular6........ Commented Oct 10, 2018 at 6:30
  • can you try compiling in visual studio code and view output? Commented Oct 11, 2018 at 3:33
  • Have you managed to come up with a solution for this issue? Commented Mar 8, 2019 at 1:49

5 Answers 5

12
  • 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.

Sign up to request clarification or add additional context in comments.

2 Comments

How do you "deploy in production mode"?
In my case I had web.config file that was getting updated with an ASPNETCORE_ENVIRONMENT variable during the publish process.
1

Note the pertinent part of the error **npm** is not recognized as an inernal or external command.

I was getting this error on a fresh Windows and VS install. Turns out that despite choosing the node.js development tools in the VS installer, node wasn't actually installed, so neither was npm.

You can test this by running node -v as the command prompt.

Solved for me by installing node. Note you may also have to do an npm install to download the dependencies in node_modules if you don't have them.

Comments

0
  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

Comments

0

I installed node.js and ready, I solved the problem. So please install node.js and it should work

Comments

0

Select the node modules present Folder open on CMD Window

npm start

*** Any error occurs like software installation Failed. Give this command

npm install

*** After completion of npm install without error

npm start.

Get the IP from output and change the local host number in asp.net project.Then run the project it works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.