ngx-quill: Angular Universal Break
Hi, I’m using this library in my Angular Universal App, however once I add it, it breack the server after running my server it immediately stops with the following error:
/node_modules/quill/dist/quill.js:7450
var elem = document.createElement('div');
^
ReferenceError: document is not defined
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 107 (51 by maintainers)
You could work around this by creating an empty mock of ngx-quill module - and during compilation replace the the real module with the empty mock for the server build.
ngx-quill empty mock could be:
I use Webpack - and during my server build, I replace the real module with the mock using NormalModeReplaceMentPlugin. I have a separate config for the server build:
It works well - and I’ve done it with a few other libraries too.
There is even an example Link in the readme to a Universal project + live Demo.
Tom Müller notifications@github.com schrieb am Mi., 5. Aug. 2020, 20:20:
@KillerCodeMonkey While you’re right it is a problem with image-resize, it also is a problem with several other plugins. quill-image-resize-module has been forked so many times, and non of the changes seem to work well. Anyway, I went back to the nifty webpack, as I found messing with the globals creates new different errors in one of my other projects. So, I had to replace just the quill-image-resize plugin instead of quill in general, since you fixed that. (see my above webpack implementation for reference)
custom-webpack.config.js
quill.mock.server.ts
See Updated Repository
@KillerCodeMonkey Could you add styles to the Quill.forRoot() declaration so that I don’t have to keep defining it in my code like so:
Thanks!
GOT IT WORKING!!! Apparently there is a difference between quill-image-resize-module and quill-image-resize, at least in the way you import them. Perhaps somebody smarter than me with classes can explain how to get the other one working as well. Either way, what works, works. Here is my find code:
And I will try and keep my repository updated unless @KillerCodeMonkey decides to add his own version. I failed in every way possible, but it works. 😃
check my source: https://github.com/KillerCodeMonkey/ngx-quill/blob/master/src/quill-editor.component.ts#L30
@KillerCodeMonkey Yes, SSR works if you are not importing modules like ImageResize… Plain ngx-quill works on SSR