aspnet / JavaScriptServices

[Archived] This repository has been archived
Apache License 2.0
3.03k stars 518 forks source link

Prerendering of views and window object missing? #1147

Closed darewreck54 closed 7 years ago

darewreck54 commented 7 years ago

Hi,

I'm currently trying to use powerbi-client library in my reactredux application. However, when I use it i get the following exception:

Exception: Call to Node module failed with error: Prerendering failed because of error: ReferenceError: window is not defined

I believe this is because it tries to preRender some of the views and the views depend on a library that utilize the window object, but the window object does not exist on the server side.

Is disabling the prerender feature the only way to get around this problem? Any advice appreciated, Thanks, Derek

stephtr commented 7 years ago

One option that comes into my mind would be to render the component only on the client.

SteveSandersonMS commented 7 years ago

Agreed with @stephtr - you will need to put some logic around any code that tries to reference window so that it doesn't run during server-side prerendering. For example, use a check like if (typeof window !== 'undefined') { ... run client-side code ... }.

cahitbeyaz commented 7 years ago

what about import 'xyz'. you can not put something like if in the import section

J0hnRoger commented 7 years ago

My use case was to use an external library wich attach an object to the global jQuery '$'. So it couldn't be used in server side. I finally added the import of the external lib only in the boot-client.ts file in order to being include only in client side.

baughmann commented 6 years ago

@J0hnRoger How did you go about using that library elsewhere in your application after importing it in your boot-client.ts file?