Javascriptservices: Prerendering of views and window object missing?

Created on 25 Jul 2017  路  5Comments  路  Source: aspnet/JavaScriptServices

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

Most helpful comment

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.

All 5 comments

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

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

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

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dantheman999301 picture dantheman999301  路  4Comments

tmedanovic picture tmedanovic  路  4Comments

benaadams picture benaadams  路  3Comments

asadsahi picture asadsahi  路  3Comments

docrinehart picture docrinehart  路  4Comments