Usage of Quill modules in angular universal
See original GitHub issueI have already read all of the content of the following related Issues: #91 and #57.
Error:
When running dev:ssr i get the following error:
ReferenceError: document is not defined
Solutions from above mentioned issues did not help as following.
Code i need to implement
I need to implement the following code to add icons to my custom “undo” and “redo” actions.
const isBrowser = isPlatformBrowser( platformId );
if ( isBrowser ) {
const icons = Quill.import( 'ui/icons' );
icons[ 'undo' ] = quillUndoIcon;
icons[ 'redo' ] = quillRedoIcon;
}
Mocked “document” global in server.ts (not helping)
i have tried mocking the document with domino, but somehow its still saying document is not defined…
const template = fs
.readFileSync( path.join( join( process.cwd(), 'dist/lebenslauf-generator/browser' ), 'index.html' ) )
.toString();
// Shim for the global window and document objects.
const window = domino.createWindow( template );
global[ 'window' ] = window;
global[ 'document' ] = window.document;
Usage of quill with require
I have also tried avoiding the quill import by requiring Quill in an if isBrowser
statement:
const Quill = require( 'quill' );
const icons = Quill.import( 'ui/icons' );
icons[ 'undo' ] = quillUndoIcon;
icons[ 'redo' ] = quillRedoIcon;
while this resolved the error on compilation, it broke quill on the client.
What next?
So should i mock a quill component somehow? How would i do that? Could you provide a mocked version for the server or something?
Also i dont quite understand: We would mock the ngx-quill component but i dont think this would fix the problem which is caused by the following import:
import Quill from 'quill';
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (5 by maintainers)
Keep in mind to check if you are in browser and the service function is returning an observable you need to subscribe 😉.
Feel free to send a pr 😃
Jeremias Nater @.***> schrieb am Di., 1. März 2022, 09:37: