Alcumus/react-doc-viewer

window is not defined in SSR

venkateswaran-b opened this issue · 3 comments

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?

having same issue in Gatsby app

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>

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