Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.0+ doesn't work with ssr #173

Closed
glemiere opened this issue Oct 1, 2017 · 17 comments
Closed

2.0.0+ doesn't work with ssr #173

glemiere opened this issue Oct 1, 2017 · 17 comments
Assignees
Labels
Milestone

Comments

@glemiere
Copy link

glemiere commented Oct 1, 2017

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
@VadimDez VadimDez added the bug label Oct 1, 2017
@derrick-babb
Copy link

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. (../server.js:172048:1)
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. (../server.js:157478:93)
at webpack_require (../server.js:26:30)
at Object.ROUTES (../server.js:151162:70)
at webpack_require (../server.js:26:30)
`
Notes:

  • "ng2-pdf-viewer": "^2.0.2",
  • Version 1.2.7 was working up until afternoon of 10/3/17.
  • pdf-viewer is used inside of a modal window.

@glemiere
Copy link
Author

glemiere commented Oct 3, 2017

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 :/

@glemiere
Copy link
Author

glemiere commented Oct 9, 2017

Any news about SSR support ?

@glemiere
Copy link
Author

up

@CanKattwinkel
Copy link

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..

@VadimDez
Copy link
Owner

Would definitely save me some time if somebody provides a repo where i can reproduce this issue.

@VadimDez VadimDez self-assigned this Nov 1, 2017
@VadimDez VadimDez modified the milestone: 2.0.4 Nov 1, 2017
@LiverpoolOwen
Copy link

@VadimDez any updates on this guys?

@VadimDez
Copy link
Owner

I'll try to finish this by the end of this week.

VadimDez added a commit that referenced this issue Nov 24, 2017
@VadimDez VadimDez mentioned this issue Nov 24, 2017
@VadimDez VadimDez added this to the 3.0.2 milestone Nov 24, 2017
@VadimDez
Copy link
Owner

Fixed in 3.0.2

@glemiere
Copy link
Author

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 ;)

@CanKattwinkel
Copy link

@glemiere c965b9a

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)

@glemiere
Copy link
Author

That's nice! Thank you!

@hesampour
Copy link

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?

@arsenlol
Copy link

arsenlol commented Oct 31, 2018

+1 for previous comment:
webpack:///./node_modules/pdfjs-dist/build/pdf.js?:1080
if (typeof Element.prototype.remove !== 'undefined') {

ReferenceError: Element is not defined

@shahbazkhan054
Copy link

shahbazkhan054 commented Jan 31, 2019

any update on this?
ReferenceError: Element is not defined

@kkorte
Copy link

kkorte commented Feb 5, 2019

@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: {}
};

@Bizotics-Dev
Copy link

@VadimDez can you check this error reproduced again in v5.3.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants