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

webpack build causes errors with server-side rendering #69

Open
williaster opened this issue Jan 12, 2021 · 2 comments
Open

webpack build causes errors with server-side rendering #69

williaster opened this issue Jan 12, 2021 · 2 comments

Comments

@williaster
Copy link

When we use this library in a server-side rendering environment, we get the error ReferenceError: window is not defined

if you look at the source, it looks like the error is at line 1:456 which maps to where window is referenced in this formatted version.

image

This means window is referenced on module import, so even if we wait to render the component until it is mounted (i.e., in the browser) we get this error from module import alone. We have a work around to lazy load the module when a parent component is mounted, but it's a lot of setup just to work.

This SO question suggests that it may be your webpack output configuration.

@acj97
Copy link

acj97 commented Feb 23, 2022

After spending some times for this problem, i found this solution
https://stackoverflow.com/questions/68596778/next-js-window-is-not-defined

you just need to use dynamic on the import

import dynamic from 'next/dynamic';
const CytoscapeComponent = dynamic(() => (import('react-cytoscapejs')), { ssr: false });

@TuanManhCao
Copy link

Good stuff @acj97 , I solve this problem in the same way.

However got another one, when I tried to use CytoScape with Layout extension. For example when I use it with cola layout I cannot register the layout before rendering CytoScapeComponent, I think it's the problem with how Dynamic Component is being loaded.

Have you come across the same thing?

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

No branches or pull requests

3 participants