Hi!
Everything is working fine using webpack and ssr with the version 1.2.7.
However since version 2.0.0 I get the following error when I start my dist/server.js file.
window['pdfjs-dist/build/pdf'] = pdfjs;
^
ReferenceError: window is not defined
Angular Universal also breaks with the same error during server-side rendering, where the window object is not available:
`
window['pdfjs-dist/build/pdf'] = pdfjs;
^
ReferenceError: window is not defined
at Object.
at __webpack_require__ (../server.js:26:30)
at Object.defineProperty.value (../server.js:172035:30)
at __webpack_require__ (../server.js:26:30)
at Object.defineProperty.value (../server.js:159976:73)
at __webpack_require__ (../server.js:26:30)
at Object.
at __webpack_require__ (../server.js:26:30)
at Object.ROUTES (../server.js:151162:70)
at __webpack_require__ (../server.js:26:30)
`
Notes:
I found a workaround adding the following to my webpack.server.config.js
//Temporary fix for ng2-pdf-viewer undefined server-side variables.
new webpack.DefinePlugin({
window: [],
document: {}
})
However then I have a new problem with Zone :
/dist/server.js:105226
Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) {
^
I guess this library doesn't support SSR anymore :/
Any news about SSR support ?
up
I'm currently searching for an PDF viewer that supports Angular Universal. Are there any news on this issue? Would a reproduction repository help?
I don't really need PDF viewer on server side - maybe a simple solution would be to provide a noop-Module like the noopanimationsmodule..
Would definitely save me some time if somebody provides a repo where i can reproduce this issue.
@VadimDez any updates on this guys?
I'll try to finish this by the end of this week.
Fixed in 3.0.2
Awesome! I'll test soon! ;-)
Thank you for your work!
Could you provide us a few explanation on the way you fixed this ? Could be interesting ;)
@glemiere https://github.com/VadimDez/ng2-pdf-viewer/pull/216/commits/c965b9ab8291a49c4c54f28c7b12af19b7180a7a
You can either wrap the Window/document statements with if checks or use the document provided via dependency injection (supports querySelector and so on on server side since Angular 5 I think)
That's nice! Thank you!
Hi. I have problem in universal with the error Element is not defined. I found that the problem is for this component. Any Idea to fix that?
+1 for previous comment:
webpack:///./node_modules/pdfjs-dist/build/pdf.js?:1080
if (typeof Element.prototype.remove !== 'undefined') {
ReferenceError: Element is not defined
any update on this?
ReferenceError: Element is not defined
@hesampour @arsenlol @shahbazkhan054
any update on this?
ReferenceError: Element is not defined
We encountered the same problem, and fixed it in prerender.ts & server.ts by adding the following lines:
win.requestAnimationFrame = () => {};
global['Element'] = {
prototype: {}
};
@VadimDez can you check this error reproduced again in v5.3.4.
Most helpful comment
Hi. I have problem in universal with the error Element is not defined. I found that the problem is for this component. Any Idea to fix that?