Javascriptservices: asp-prerender-module causes unhandled exception when BrowserAnimationsModule is included

Created on 31 Jul 2017  路  12Comments  路  Source: aspnet/JavaScriptServices

The _asp-prerender-module_ , included in the index.cshtml view, doesn't seem to play nice with the BrowserAnimationsModule (from the (at)angular/platform-browser/animations file). I get the below unhandled exception whenever I import this animations module. When I replace the renderer with _asp-ng2-prerender-module_, however, everything works fine when I launch the application. However, it seems to have complications with our authentication service. Ideally, I would like to get the animations module working with asp-prerender-module:

This line of code causes issues with _BrowserAnimationsModule_:
<app asp-prerender-module="ClientApp/dist/main-server" asp-prerender-data="Options.Value">Loading...</app>

This line does not, however, it appears to cause complications with our implemented auth service:
<app asp-ng2-prerender-module="ClientApp/dist/main-server">Loading...</app>

An unhandled exception occurred while processing the request.

Exception: Call to Node module failed with error: ReferenceError: document is not defined
at DefaultDomRenderer2.module.exports.DefaultDomRenderer2.selectRootElement (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:47809:72)
at BaseAnimationRenderer.selectRootElement (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\main-server.js:10852:106)
at createElement (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:9483:23)
at createViewNodes (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:12449:44)
at createRootView (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:12378:5)
at Object.createProdRootView [as createRootView] (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:13061:12)
at ComponentFactory_.module.exports.ComponentFactory_.create (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:10169:46)
at ComponentFactoryBoundToModule.module.exports.ComponentFactoryBoundToModule.create (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:3586:29)
at ApplicationRef_.module.exports.ApplicationRef_.bootstrap (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:5075:57)
at D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:4858:81
Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance+d__7.MoveNext()

Stack Query Cookies Headers
Exception: Call to Node module failed with error: ReferenceError: document is not defined at DefaultDomRenderer2.module.exports.DefaultDomRenderer2.selectRootElement (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:47809:72) at BaseAnimationRenderer.selectRootElement (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\main-server.js:10852:106) at createElement (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:9483:23) at createViewNodes (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:12449:44) at createRootView (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:12378:5) at Object.createProdRootView [as createRootView] (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:13061:12) at ComponentFactory_.module.exports.ComponentFactory_.create (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:10169:46) at ComponentFactoryBoundToModule.module.exports.ComponentFactoryBoundToModule.create (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:3586:29) at ApplicationRef_.module.exports.ApplicationRef_.bootstrap (D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:5075:57) at D:\gitrepo\auth\src\Bentley.Api.Management.Angular\ClientApp\dist\vendor.js:4858:81
Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance+d__7.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance+d__13.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.NodeServices.NodeServicesImpl+d__10.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.SpaServices.Prerendering.PrerenderTagHelper+d__33.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner+d__0.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
AspNetCore._Views_Home_Index_cshtml+d__35.MoveNext() in Index.cshtml
+
Loading...
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Razor.RazorView+d__14.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Razor.RazorView+d__13.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor+d__18.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewResult+d__26.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__30.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__28.MoveNext()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResultExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__22.MoveNext()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__20.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Builder.RouterMiddleware+d__4.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware+d__6.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware+d__6.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+d__7.MoveNext()

Show raw exception details

Most helpful comment

I had the same issue when using the BrowserAnimationsModule.
Try changing the "asp-prerender-module" to "asp-ng2-prerender-module" in the index

All 12 comments

Are you using/importing the NoopAnimationsModule in the server bundle?
If yes, it seems to be similar to angular/#15098, where a workaround has been posted.

I tried importing the _BrowserAnimationsModule_ into just the client module and the _NoopAnimationsModule_ into the server module, as suggested. I also added this bit of code into the server module with no luck:

// declarations
export function instantiateServerRendererFactory(
  renderer: RendererFactory2, engine: 傻AnimationEngine, zone: NgZone) {
   return new 傻AnimationRendererFactory(renderer, engine, zone);
}


const createRenderer = 傻ServerRendererFactory2.prototype.createRenderer;
傻ServerRendererFactory2.prototype.createRenderer = function () {
  const result = createRenderer.apply(this, arguments);
  const setProperty = result.setProperty;
  result.setProperty = function () {
    try {
      setProperty.apply(this, arguments);
    } catch (e) {
      if (e.message.indexOf('Found the synthetic') === -1) {
        throw e;
      }
    }
  };
  return result;
}

export const SERVER_RENDER_PROVIDERS = [
  {
    provide: RendererFactory2,
    useFactory: instantiateServerRendererFactory,
    deps: [傻ServerRendererFactory2, 傻AnimationEngine, NgZone]
  }
];

I keep getting the following error, which seems to be different from the error people were getting in that fix:

An unhandled exception occurred while processing the request.

WinHttpException: The connection with the server was terminated abnormally
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

HttpRequestException: An error occurred while sending the request.
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

System.Net.Http.WinHttpException (0x80072EFF): The connection with the server was terminated abnormally
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Net.Http.WinHttpHandler.<StartRequest>d__103.MoveNext()

HttpRequestException: An error occurred while sending the request.
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Net.Http.HttpClient+<FinishSendAsync>d__58.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance+<InvokeExportAsync>d__7.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance+<InvokeExportAsync>d__13.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.NodeServices.NodeServicesImpl+<InvokeExportWithPossibleRetryAsync>d__10.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.SpaServices.Prerendering.PrerenderTagHelper+<ProcessAsync>d__33.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner+<RunAsync>d__0.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
AspNetCore._Views_Home_Index_cshtml+<ExecuteAsync>d__35.MoveNext() in Index.cshtml
+
<app asp-prerender-module="ClientApp/dist/main-server" asp-prerender-data="Options.Value">Loading...</app>
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Razor.RazorView+<RenderPageAsync>d__14.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Razor.RazorView+<RenderAsync>d__13.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor+<ExecuteAsync>d__18.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewResult+<ExecuteResultAsync>d__26.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeResultAsync>d__30.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeNextResultFilterAsync>d__28.MoveNext()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResultExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeNextResourceFilter>d__22.MoveNext()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeAsync>d__20.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Builder.RouterMiddleware+<Invoke>d__4.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware+<Invoke>d__6.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware+<Invoke>d__6.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+<Invoke>d__7.MoveNext()

I'm not sure what specifically is going on in your case, but it looks like the error you're reporting most recently is unrelated to the changes for BrowserAnimationsModule.

With the latest .NET Core 2.0 SDK and the angular template it includes, I've verified that BrowserAnimationsModule/NoopAnimationsModule work as expected. Example: https://github.com/aspnet/JavaScriptServices/commit/c0c47e3def208873c470a524a826f8d235a5f9de

Since this seems to be working OK, I'll mark this closed. If you're still able to reproduce the issue with the current templates, could you file it as a new issue with repro steps? Thanks!

@SteveSandersonMS Also running into this problem. What is the repo URL for the working version? It looks like it's been moved around a few times.

@SteveSandersonMS I also have the problem. Used the templates from VS 2017 15.3.3, upgraded angular modules to 4.4.3. Everything works fine in development mode (IIS Express in VS2017) but when I publish to Azure out-of-the-box website (App + SQL) it fails on pre-rendering with:

NodeInvocationException: Attempt to connect to Node timed out after 60000ms.

When I try disabling the line:

<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>

...the app works but server side pre-rendering obviously doesn't, so I enabled the above line again.

I have tried importing (import: and imports[] the BrowserAnimationsModule in app.module.browser and NoopAnimationsModule in app.module.server.

Still same issue. It's unclear what the workaround linked to actually is...

Please help!

I've been dealing with this issue for days now. Why has it been 'closed'.

Can we please get some assistance here. I've followed all recommendations.

And you thought DLL hell was bad...

I had the same issue when using the BrowserAnimationsModule.
Try changing the "asp-prerender-module" to "asp-ng2-prerender-module" in the index

Had the same issue with the latest and greatest, VS2017 15.4.5, as of 7 Dec 2017. Using the asp-ng-prerender-module resolves my problem but it I don't think this issue should have been closed.

@ssfarkas Thank you, your solution works for me.

This solution works partially for me. I am also using asp-prerender-data TagHelper to bind some config data which drives some logic in createServerRenderer. After changing "asp-prerender-module" to "asp-ng2-prerender-module" the logic is not working anymore as I am not getting the config data. I have changed asp-prerender-data to asp-ng2-prerender-data but it dint help. Any help is appreciated here.

Also I could not find any documentation specific to asp-ng2-prerender-module. Some info relating to the same will also be helpful.

Thanks.

What is the correct resolution here? asp-ng2-prerender-module seems to disable SSR. What is the resolution for BrowserAnimationsModule with SSR

We host our site in Azure and the solution for me was to add this config key/value to the Application settings.

Key: WEBSITE_NODE_DEFAULT_VERSION
Value: 6.9.1

I suppose you could also add it to your appsetting.json or web.config as well.

Was this page helpful?
0 / 5 - 0 ratings