#Internal server error: document is not defined in Angular@17.0.0 SSR

12 messages · Page 1 of 1 (latest)

frail burrow
#

Hey guys, I got a problem with Angular SSR, one of my dependencies require "document" but I can't figure out how to do that. I tried adding a global document in polyfills but it failed. Is there a way to make it work ?

ancient adder
#

Hello , if thried library the only solutions if usage isPlataformBrowser for indicate the code only execute in browser , because remember the SSR execute between Server & Browser but some library usage global object like window or document only exist in browser.
If is your own library considere usage DOCUMENT in contructor or inyect
// Usage plataformBrowser
https://www.geeksforgeeks.org/angular10-isplatformbrowser-function/

// Usage DOCUMENT
https://www.c-sharpcorner.com/blogs/quick-tip-injecting-document-in-angular-component

In this quick tutorial, we'll be injecting document object inside an Angular component.

frail burrow
ancient adder
#

As I remember, at the time it was not possible to do almost anything to make the library SSR Friendly in Angular Universal, unless you modify it yourself or force it to only be executed in the browser (which is the most viable).
Even in my case I had to create a fork of the library and make it compatible with Angular Universal on my own as a last option.

frail burrow
#

And there is no way to create a polyfills ?

ancient adder
#

As far as I investigated a few months ago it was not possible, the closest thing was the "Domino" DOCUMENT that is already being implemented in Angular with Inject

#

ohter options if remember good if it's only a page not need SSR is possible only send how JS , That is, it does not render the server, only the JS, so to speak.

frail burrow
#

Well, ok thanks, I should be able to patch this by finding another library cause it's just quill.js that is an html editor so shouldn't be hard to find an equivalent, but seems like that wouldn't be the only error trying to make SSR work xD

#

Got problems with PWA too sooooo ...

#

And zone.js imports xD

round crystal
#

Could you not render that component on the server?