[Fixed] ASP.Net MVC Core: The prerendering build process did not complete within the timeout period of 50 seconds

Issue

I have ASP.Net MVC Core (2.1.0), with SPA Prerendering.

I’m getting a timeout from within my JWT Token Middleware, in the line “await next()”.

I started getting the error when I updated my @angular/cli to the latest version (v6.0.8), which also added @angular-devkit/build-angular (v0.6.8).

I don’t get any errors when running “ng build”.

public static class JwtTokenMiddleware
{
    public static IApplicationBuilder UseJwtTokenMiddleware(this IApplicationBuilder app, string schema = JwtBearerDefaults.AuthenticationScheme)
    {
        return app.Use(async (ctx, next) =>
        {
            if (ctx.User.Identity?.IsAuthenticated != true)
            {
                var result = await ctx.AuthenticateAsync(schema);
                if (result.Succeeded && result.Principal != null)
                {
                    ctx.User = result.Principal;
                }
            }

            await next();
        });
    }
}

Stacktrace:

System.TimeoutException: The prerendering build process
did not complete within the timeout period of 50 seconds. Check the
log output for error information. at
Microsoft.AspNetCore.SpaServices.Extensions.Util.TaskTimeoutExtensions.WithTimeout(Task
task, TimeSpan timeoutDelay, String message) at
Microsoft.AspNetCore.Builder.SpaPrerenderingExtensions.<>c__DisplayClass0_0.<b__1>d.MoveNext()
— End of stack trace from previous location where exception was thrown — at
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext
httpContext) at
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext
context) at
MyProject.JwtTokenMiddleware.<>c__DisplayClass0_0.<b__0>d.MoveNext()
in
/MyProject/UseJwtTokenMiddleware.cs:line
23
— End of stack trace from previous location where exception was thrown — at
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext
context) at
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext
context) at
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext
context)

UPDATE:

The angular-cli upgrade replaced some settings. The original .angular-cli.json file had setting for the server-side rendering folder. That was gone with the new angular.json file the upgrade rewrote. That’s why ASP.Net could not find it. I now have to put the SSR settings back in angular.json file.

UPDATE 2:

The docs at https://angular.io/guide/universal#angular-cli-configuration outlines what to put in angular.json.

Solution

In startup.cs file, go to the IsDevelopment part of the code and add the following lines:

if (env.IsDevelopment())
{
    //Time limit extended
    spa.Options.StartupTimeout = new TimeSpan(days: 0, hours: 0, minutes: 1, seconds: 30);
    //Time limit extended
    spa.UseAngularCliServer(npmScript: "start");
}

Reference : https://github.com/aspnet/JavaScriptServices/issues/1512

Leave a Reply

(*) Required, Your email will not be published