question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

modal service breaks universal server side rendering

See original GitHub issue

Bug description:

The modal service seems to be causing a bug that prevents server side rendering from working properly. I realize this is still a feature in development, but I wanted to make a note of it, and it didn’t seem like a bug report had been posted yet.

You can use the universal-starter repo to clone a test application:

https://github.com/angular/universal-starter

Compile and run on localhost using two npm scripts:

npm run build:ssr npm run serve:ssr

When NgbModule.forRoot() is added to the root NgModule, everything is working fine. However, when NgbModal is injected into a component, the below error message occurs after compilation and attempting to visit localhost.

Error message:

Error: No component factory found for NgbModalBackdrop. Did you add it to @NgModule.entryComponents? at noComponentFactoryError (C:\Users\Alec\nodeprojects\testapp\dist\server.js:4059:34) at CodegenComponentFactoryResolver.resolveComponentFactory (C:\Users\Alec\nodeprojects\testapp\dist\server.js:4123:19) at new NgbModalStack (C:\Users\Alec\nodeprojects\testapp\dist\server.js:62589:59) at _createClass (C:\testapp\dist\server.js:10896:20) at _createProviderInstance$1 (C:\Users\Alec\nodeprojects\testapp\dist\server.js:10866:26) at resolveNgModuleDep (C:\Users\Alec\nodeprojects\testapp\dist\server.js:10851:17) at _createClass (C:\Users\Alec\nodeprojects\testapp\dist\server.js:10896:107) at _createProviderInstance$1 (C:\Users\Alec\nodeprojects\testapp\dist\server.js:10866:26) at resolveNgModuleDep (C:\Users\Alec\nodeprojects\testapp\dist\server.js:10851:17) at NgModuleRef_.get ``(C:\Users\Alec\nodeprojects\testapp\dist\server.js:12076:16)

Version of Angular, ng-bootstrap, and Bootstrap:

Angular: 5.0.0

ng-bootstrap: 1.0.0-beta.5

Bootstrap: 4.0.0-beta.2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
elSuperRitoncommented, Dec 8, 2017

@JinnaBalu Same here. Window is not defined. Been on this problem for ages ! Did you find how to get around this ?

0reactions
belobradcommented, Dec 24, 2017

This worked for me as a temp fix:

function NgbModalStack(_applicationRef, _injector, _componentFactoryResolver) { this._applicationRef = _applicationRef; this._injector = _injector; this._componentFactoryResolver = _componentFactoryResolver; this._backdropFactory = (typeof window !== 'undefined') ? _componentFactoryResolver.resolveComponentFactory(NgbModalBackdrop) : NgbModalBackdrop; this._windowFactory = (typeof window !== 'undefined') ? _componentFactoryResolver.resolveComponentFactory(NgbModalWindow) : NgbModalWindow; }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Page crash after converting to Angular Universal (SSR)
It seems like I'm trying to call getBoundingClientRect function but I don't have that in any of my codes. Any idea on how...
Read more >
Universal Javascript in Production - Server/Client Rendering
In this post, I am now going to dive into how we are using Universal Javascript and Node.js to enable server and client...
Read more >
The Ultimate Ionic Server Side Rendering Guide (SSR)
With Angular Universal we can use Server Side Rendering in our Ionic apps, and since there's a new package which makes our Ionic...
Read more >
Angular Universal: Complete Practical Guide
Another reason for doing server-side rendering is to make our application more search engine friendly. Today, most search engines take the title ...
Read more >
Server-side rendering with Vue and Nuxt.js - LogRocket Blog
By selecting universal , you're telling Nuxt that you want your app to be able to run on both the server-side and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found