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

window is not defined in SSR #124

Open
venkateswaran-b opened this issue Mar 14, 2023 · 3 comments
Open

window is not defined in SSR #124

venkateswaran-b opened this issue Mar 14, 2023 · 3 comments

Comments

@venkateswaran-b
Copy link

venkateswaran-b commented Mar 14, 2023

While using react-doc-viewer in frameworks with SSR like Next.js or Gatsby there is an error in the line while the build phase

window.requestAnimationFrame(resolve);

ReferenceError: window is not defined

Error occurs in node_modules/pdfjs-dist/lib/web/ui_utils.js:564:3
version: 0.1.5
Can someone help in this?

@kzazarashvili
Copy link

having same issue in Gatsby app

@dev-smart-ui
Copy link

dev-smart-ui commented Mar 23, 2023

Hey!
Try just import component with DocViewer as React Lazy component.

const DocumentViewer = React.lazy(() => import("../DocumentViewer/index"))

and render it

<Suspense fallback={<Loader />}>
                <DocumentViewer
                  key={fileUrl}
                  fileUrl={fileUrl}
                  filename={fileName}
                />
              </Suspense>

@syafiqfaiz-bina
Copy link

Hey! Try just import component with DocViewer as React Lazy component.

const DocumentViewer = React.lazy(() => import("../DocumentViewer/index"))

and render it

<Suspense fallback={<Loader />}>
                <DocumentViewer
                  key={fileUrl}
                  fileUrl={fileUrl}
                  filename={fileName}
                />
              </Suspense>

This works, but how do I import the the renderer as well?

for example this what we import
import DocViewer, { DocViewerRenderers, IDocument } from 'react-doc-viewer';

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

4 participants