Topic: MDBootstrap Angular – Universal server side rendering errors
nemesh pro asked 7 years ago
Hi, I bought MDBootstrap Angular version and tried using it with aspnetcore-angular2-universal.
I gave alot of errors like KeyboardEvent is not defined, window is not defined, MouseEvent is not defined.
After searching for a few minutes, I found the problem is with the MDBootstrap Angular code itself.
If window, KeyboardEvent, MouseEvent, or event is used in constructor or ngOninit or hostListener, it throws an error since the code is still rendering on server and not yet transferred to client's browser.
Please go through these documents regarding the same.
https://github.com/MarkPieszak/aspnetcore-angular2-universal#gotchas
http://brianflove.com/2016/10/10/angular-2-window-scroll-event-using-hostlistener/
https://malcoded.com/posts/server-rendering-pitfalls
Can MDBootstrap angular be made compatible with Server Side Rendering?
beachjf pro answered 6 years ago
Damian Gemza staff commented 6 years ago
Dear Beachjf, did you read our configuration tutorial? For AGM and HammerJS you have to add those two modules to your whitelist in your webpack.config file. Here's link to the tutorial: https://mdbootstrap.com/angular/angular-universal/ Please configure your SSR with advices from my link, and everything should work just fine. Best Regards, DamianDamian Gemza staff answered 6 years ago
target: 'node', externals: [nodeExternals({ whitelist: [ /^@agm/core/, /^hammerjs/ ] })],
beachjf pro commented 6 years ago
Hi Damian, this is a GREAT news. Thank you so much :) you just made my year.Damian Gemza staff commented 6 years ago
Release is ready to use! Feel free to update your project and test our Universal compatibility.id90travel pro commented 6 years ago
This is still not working for me. I still get the KeyboardEvent is not defined error.beachjf pro answered 6 years ago
Hosboss pro answered 6 years ago
nemesh pro answered 7 years ago
Dawid Adach pro commented 7 years ago
Hi Namesh, thanks for the link. We didn't test it with angular universal yet. I know that some of our customers were working on that. We have this in our Idea list however for now I cannot provide you with estimated delivery time as we are focusing on adding new components to Angular version to align it with jQuery.beachjf pro commented 6 years ago
@nemesh, what you did we hammer.js issue ? NodeInvocationException: Prerendering failed because of error: ReferenceError: window is not defined thanks a lotFREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: No
- Provided link: Yes