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

Element type is invalid in PageInternal.render after upgrade to Webpack 4 #248

Closed
3 tasks done
iki opened this issue Jul 25, 2018 · 11 comments
Closed
3 tasks done

Element type is invalid in PageInternal.render after upgrade to Webpack 4 #248

iki opened this issue Jul 25, 2018 · 11 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed stale
Milestone

Comments

@iki
Copy link

iki commented Jul 25, 2018

Before you start - checklist

  • I followed instructions in documentation written for my React-PDF version
  • I have checked if this bug is not already reported
  • I have checked if an issue is not listed in Known issues

Description
After upgrade to webpack 4, when we try to show the PDF, the application resets to blank screen on any browser (see below) and the preserved console log shows an uncaught error Element type is invalid in PageInternal.render. See below for full console log. The same code works ok when built with webpack 3.

Steps to reproduce
N/A, the source, where we encounter this issue, is not open.

Expected behavior
Displaying PDF using react-pdf should continue to work after upgrade to webpack4.

Environment

  • Browser: Current Chrome dev ( 69.0.3493.3), or Opera dev (56.0.3013.0), or IE11
  • React-PDF version: 4.0.0-beta, 4.0.0-beta.2 with either pdfjs-dist 2.0.489 or experimental 2.0.550

Additional information
Linking to the general webpack 4 compatibility issue #179.

And here's the full log:

19:30:01.636 webpack-internal:///../node_modules/fbjs/lib/warning.js:33 Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `PageInternal`.
    in PageInternal
    in Page (created by PdfViewer)
    in div (created by Document)
    in Document (created by PdfViewer)
    in div (created by DialogContent)
    in DialogContent (created by WithStyles(DialogContent))
    in WithStyles(DialogContent) (created by PdfViewer)
    in div (created by PdfViewer)
    in div (created by Paper)
    in Paper (created by WithStyles(Paper))
    in WithStyles(Paper) (created by Dialog)
    in Transition (created by Fade)
    in Fade (created by WithTheme(Fade))
    in WithTheme(Fade) (created by Dialog)
    in RootRef (created by Modal)
    in div (created by Modal)
    in Portal (created by Modal)
    in Modal (created by WithStyles(Modal))
    in WithStyles(Modal) (created by Dialog)
    in Dialog (created by WithStyles(Dialog))
    in WithStyles(Dialog) (created by PdfViewer)
    in PdfViewer (created by WithStyles(PdfViewer))
    in WithStyles(PdfViewer) (created by withHandlers(WithStyles(PdfViewer)))
    in withHandlers(WithStyles(PdfViewer)) (created by withState(withHandlers(WithStyles(PdfViewer))))
    in withState(withHandlers(WithStyles(PdfViewer))) (created by withState(withState(withHandlers(WithStyles(PdfViewer)))))
    in withState(withState(withHandlers(WithStyles(PdfViewer)))) (created by withState(withState(withState(withHandlers(WithStyles(PdfViewer))))))
    in withState(withState(withState(withHandlers(WithStyles(PdfViewer))))) (created by withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer)))))))
    in withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer)))))) (created by branch(withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer))))))))
    in branch(withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer))))))) (created by Connect(branch(withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer)))))))))
    in Connect(branch(withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer)))))))) (created by ToolTip)
    in div (created by ToolTip)
    in ToolTip (created by WithStyles(ToolTip))
    in WithStyles(ToolTip) (created by lifecycle(WithStyles(ToolTip)))
    in lifecycle(WithStyles(ToolTip)) (created by Connect(lifecycle(WithStyles(ToolTip))))
    in Connect(lifecycle(WithStyles(ToolTip))) (created by withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))
    in withHandlers(Connect(lifecycle(WithStyles(ToolTip)))) (created by withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip))))))
    in withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip))))) (created by withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))))
    in withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))) (created by withState(withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip))))))))
    in withState(withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip))))))) (created by branch(withState(withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))))))
    in branch(withState(withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))))) (created by KpiChart)
    in div (created by KpiChart)
    in div (created by KpiChart)
    in KpiChart (created by WithStyles(KpiChart))
    in WithStyles(KpiChart) (created by lifecycle(WithStyles(KpiChart)))
    in lifecycle(WithStyles(KpiChart)) (created by withPropsOnChange(lifecycle(WithStyles(KpiChart))))
    in withPropsOnChange(lifecycle(WithStyles(KpiChart))) (created by withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))
    in withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))) (created by withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))))
    in withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))) (created by withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))))
    in withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))) (created by withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))))))
    in withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))))) (created by withState(withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))))))
    in withState(withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))))) (created by withState(withState(withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))))))))
    in withState(withState
printWarning @ webpack-internal:///../node_modules/fbjs/lib/warning.js:33
19:30:01.637 webpack-internal:///../node_modules/fbjs/lib/invariant.js:49 Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `PageInternal`.
    at invariant (webpack-internal:///../node_modules/fbjs/lib/invariant.js:42)
    at throwOnInvalidElementType (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:5393)
    at createFiberFromElement (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:5359)
    at createChild (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:7554)
    at reconcileChildrenArray (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:7805)
    at reconcileChildFibers (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:8121)
    at reconcileChildrenAtExpirationTime (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:8240)
    at reconcileChildren (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:8231)
    at updateFragment (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:8268)
    at beginWork (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:9004)
19:30:01.692 webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:9643 The above error occurred in one of your React components:
    in div (created by PageInternal)
    in PageInternal
    in Page (created by PdfViewer)
    in div (created by Document)
    in Document (created by PdfViewer)
    in div (created by DialogContent)
    in DialogContent (created by WithStyles(DialogContent))
    in WithStyles(DialogContent) (created by PdfViewer)
    in div (created by PdfViewer)
    in div (created by Paper)
    in Paper (created by WithStyles(Paper))
    in WithStyles(Paper) (created by Dialog)
    in Transition (created by Fade)
    in Fade (created by WithTheme(Fade))
    in WithTheme(Fade) (created by Dialog)
    in RootRef (created by Modal)
    in div (created by Modal)
    in Portal (created by Modal)
    in Modal (created by WithStyles(Modal))
    in WithStyles(Modal) (created by Dialog)
    in Dialog (created by WithStyles(Dialog))
    in WithStyles(Dialog) (created by PdfViewer)
    in PdfViewer (created by WithStyles(PdfViewer))
    in WithStyles(PdfViewer) (created by withHandlers(WithStyles(PdfViewer)))
    in withHandlers(WithStyles(PdfViewer)) (created by withState(withHandlers(WithStyles(PdfViewer))))
    in withState(withHandlers(WithStyles(PdfViewer))) (created by withState(withState(withHandlers(WithStyles(PdfViewer)))))
    in withState(withState(withHandlers(WithStyles(PdfViewer)))) (created by withState(withState(withState(withHandlers(WithStyles(PdfViewer))))))
    in withState(withState(withState(withHandlers(WithStyles(PdfViewer))))) (created by withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer)))))))
    in withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer)))))) (created by branch(withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer))))))))
    in branch(withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer))))))) (created by Connect(branch(withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer)))))))))
    in Connect(branch(withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer)))))))) (created by ToolTip)
    in div (created by ToolTip)
    in ToolTip (created by WithStyles(ToolTip))
    in WithStyles(ToolTip) (created by lifecycle(WithStyles(ToolTip)))
    in lifecycle(WithStyles(ToolTip)) (created by Connect(lifecycle(WithStyles(ToolTip))))
    in Connect(lifecycle(WithStyles(ToolTip))) (created by withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))
    in withHandlers(Connect(lifecycle(WithStyles(ToolTip)))) (created by withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip))))))
    in withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip))))) (created by withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))))
    in withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))) (created by withState(withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip))))))))
    in withState(withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip))))))) (created by branch(withState(withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))))))
    in branch(withState(withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))))) (created by KpiChart)
    in div (created by KpiChart)
    in div (created by KpiChart)
    in KpiChart (created by WithStyles(KpiChart))
    in WithStyles(KpiChart) (created by lifecycle(WithStyles(KpiChart)))
    in lifecycle(WithStyles(KpiChart)) (created by withPropsOnChange(lifecycle(WithStyles(KpiChart))))
    in withPropsOnChange(lifecycle(WithStyles(KpiChart))) (created by withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))
    in withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))) (created by withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))))
    in withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))) (created by withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))))
    in withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))) (created by withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))))))
    in withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))))) (created by withState(withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))))))
    in withState(withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))))) (created by withState(withState(withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))))))))
    in withState(withState(withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))))))) (created by withState(withState(withState(withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)
logCapturedError @ webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:9643
19:30:01.692 webpack-internal:///../node_modules/react-hot-loader/dist/react-hot-loader.development.js:175 Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `PageInternal`.
    at invariant (webpack-internal:///../node_modules/fbjs/lib/invariant.js:42)
    at throwOnInvalidElementType (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:5393)
    at createFiberFromElement (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:5359)
    at createChild (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:7554)
    at reconcileChildrenArray (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:7805)
    at reconcileChildFibers (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:8121)
    at reconcileChildrenAtExpirationTime (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:8240)
    at reconcileChildren (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:8231)
    at updateFragment (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:8268)
    at beginWork (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:9004)
error @ webpack-internal:///../node_modules/react-hot-loader/dist/react-hot-loader.development.js:175
19:30:02.121 webpack-internal:///../node_modules/fbjs/lib/warning.js:33 Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
    in PageInternal
    in Page (created by PdfViewer)
    in div (created by Document)
    in Document (created by PdfViewer)
    in div (created by DialogContent)
    in DialogContent (created by WithStyles(DialogContent))
    in WithStyles(DialogContent) (created by PdfViewer)
    in div (created by PdfViewer)
    in div (created by Paper)
    in Paper (created by WithStyles(Paper))
    in WithStyles(Paper) (created by Dialog)
    in Transition (created by Fade)
    in Fade (created by WithTheme(Fade))
    in WithTheme(Fade) (created by Dialog)
    in RootRef (created by Modal)
    in div (created by Modal)
    in Portal (created by Modal)
    in Modal (created by WithStyles(Modal))
    in WithStyles(Modal) (created by Dialog)
    in Dialog (created by WithStyles(Dialog))
    in WithStyles(Dialog) (created by PdfViewer)
    in PdfViewer (created by WithStyles(PdfViewer))
    in WithStyles(PdfViewer) (created by withHandlers(WithStyles(PdfViewer)))
    in withHandlers(WithStyles(PdfViewer)) (created by withState(withHandlers(WithStyles(PdfViewer))))
    in withState(withHandlers(WithStyles(PdfViewer))) (created by withState(withState(withHandlers(WithStyles(PdfViewer)))))
    in withState(withState(withHandlers(WithStyles(PdfViewer)))) (created by withState(withState(withState(withHandlers(WithStyles(PdfViewer))))))
    in withState(withState(withState(withHandlers(WithStyles(PdfViewer))))) (created by withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer)))))))
    in withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer)))))) (created by branch(withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer))))))))
    in branch(withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer))))))) (created by Connect(branch(withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer)))))))))
    in Connect(branch(withState(withState(withState(withState(withHandlers(WithStyles(PdfViewer)))))))) (created by ToolTip)
    in div (created by ToolTip)
    in ToolTip (created by WithStyles(ToolTip))
    in WithStyles(ToolTip) (created by lifecycle(WithStyles(ToolTip)))
    in lifecycle(WithStyles(ToolTip)) (created by Connect(lifecycle(WithStyles(ToolTip))))
    in Connect(lifecycle(WithStyles(ToolTip))) (created by withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))
    in withHandlers(Connect(lifecycle(WithStyles(ToolTip)))) (created by withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip))))))
    in withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip))))) (created by withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))))
    in withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))) (created by withState(withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip))))))))
    in withState(withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip))))))) (created by branch(withState(withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))))))
    in branch(withState(withState(withProps(withHandlers(Connect(lifecycle(WithStyles(ToolTip)))))))) (created by KpiChart)
    in div (created by KpiChart)
    in div (created by KpiChart)
    in KpiChart (created by WithStyles(KpiChart))
    in WithStyles(KpiChart) (created by lifecycle(WithStyles(KpiChart)))
    in lifecycle(WithStyles(KpiChart)) (created by withPropsOnChange(lifecycle(WithStyles(KpiChart))))
    in withPropsOnChange(lifecycle(WithStyles(KpiChart))) (created by withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))
    in withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))) (created by withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))))
    in withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))) (created by withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))))
    in withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))) (created by withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))))))
    in withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))))) (created by withState(withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))))))
    in withState(withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart)))))))) (created by withState(withState(withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))))))))
    in withState(withState(withState(withState(withState(withHandlers(withPropsOnChange(lifecycle(WithStyles(KpiChart))))
printWarning @ webpack-internal:///../node_modules/fbjs/lib/warning.js:33
@wojtekmaj
Copy link
Owner

Hi, what version of React are you on?

@wojtekmaj wojtekmaj self-assigned this Jul 26, 2018
@iki
Copy link
Author

iki commented Jul 26, 2018

Hi @wojtekmaj, we use [email protected].

@wojtekmaj
Copy link
Owner

I tried to reproduce it and honestly, I'm not even able to get it working on Webpack 4. We gotta wait for Mozilla to make an official release. Then we'll deprecate Webpack 2 and Webpack 4 should be supported just fine. Keeping this open for now.

@iki
Copy link
Author

iki commented Aug 9, 2018

Thanks @wojtekmaj!
I'll try to create sample/webpack4 from your sample/webpack and reproduce the issue there. We can test the pdf.js pre/release with it and check if there's anything needed on the react-pdf side.

@wojtekmaj wojtekmaj added the enhancement New feature or request label Aug 9, 2018
@wojtekmaj wojtekmaj added this to the 4.0.0 milestone Aug 9, 2018
@wojtekmaj wojtekmaj added the help wanted Extra attention is needed label Aug 14, 2018
@wojtekmaj wojtekmaj changed the title Element type is invalid in PageInternal.render after upgrade to webpack 4 Element type is invalid in PageInternal.render after upgrade to Webpack 4 Aug 14, 2018
@drita-shujaku
Copy link

Hi, I am running into the same issue using webpack 4, [email protected] and react-pdf 5. Any updates or workarounds on this?

@yeung108
Copy link

yeung108 commented May 17, 2022

I'm running into similar issue using webpack 5, [email protected], react-pdf 5.7.2. Did I miss sth obvious?

arning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `PageInternal`.
    in PageInternal (created by Context.Consumer)
    in ForwardRef(Page) (created by PdfViewer)
    in div (created by Document)
    in Document (created by PdfViewer)
    in div (created by PdfViewer)
    ...(my app internals)

@yeung108
Copy link

I'm running into similar issue using webpack 5, [email protected], react-pdf 5.7.2. Did I miss sth obvious?


arning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.



Check the render method of `PageInternal`.

    in PageInternal (created by Context.Consumer)

    in ForwardRef(Page) (created by PdfViewer)

    in div (created by Document)

    in Document (created by PdfViewer)

    in div (created by PdfViewer)

    ...(my app internals)

The weird thing I found is...it works in storybook but not in the real code...but I'm calling the same component.

Anyone encountered the same error could give me some insight on how it's happening...?

@Jordan-Lane
Copy link

Jordan-Lane commented Jul 20, 2022

I've encountered a similar issue to @yeung108. However instead of but got: undefined I get but got: object. I am currently unable to render a PDF using Webpack 5, and react-pdf 5.7.2. I have tried both React 18.2.0 and 17.02, both result in the same error.

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of 'PageInternal'.
    at PageInternal
    at Page
    at div
    at Document
    at div
    at PdfViewer
    ... (my app)

My app is quite simple, I am currently just trying to render a single page of a document:

import React, { FunctionComponent } from 'react';
import { RouteComponentProps } from '@reach/router';
import { Document, Page, pdfjs } from 'react-pdf';

pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.js`;

const PdfViewer: FunctionComponent<RouteComponentProps> = () => {
  const onDocumentLoadError = (error: Error) => {
    console.log(`Error: ${error}`);
  };

  const onDocumentLoadSuccess = ({ numPages }: any) => {
    console.log(`Document loaded: ${numPages}`);
  };

  const onPageLoadError = (error: Error) => {
    console.log(`Page load error: ${error}`);
  };

  return (
    <div>
      <Document
        file="/images/transformers.pdf"
        onLoadSuccess={onDocumentLoadSuccess}
        onLoadError={onDocumentLoadError}
      >
        <Page pageNumber={1} onLoadError={onPageLoadError} />
      </Document>
    </div>
  );
};

export default PdfViewer;

I also checked devtools, and confirmed that I was able to get the static local pdf correctly (attached is the photo of the 200 request)
Screen Shot 2022-07-20 at 3 13 25 PM

Does anyone have any advice on how to fix this? I have tried different pdfs, importing react-pdf multiple different ways, setting up the pdf.worker in different ways and nothing has helped. Any help would be greatly appreciated!

@yeung108
Copy link

Just want to add that if I comment out the <Page/> component, it works successfully and can load the numPages of the document. So should be sth wrong with the <Page/> component itself. I also tried doing {numPages && <Page pageNumber={currentPage} />} but the same error occurs.

...
  const [numPages, setNumPages] = useState<number | null>(null);
  const [currentPage, setCurrentPage] = useState<number>(1);
  const onDocumentLoadSuccess = (pageNum: number) => {
    window.console.log(pageNum) <-- it can successfully print the number of pages of the document
    setNumPages(pageNum);
  };
  <Document
        file={url}
        onLoadSuccess={(source) => {
          onDocumentLoadSuccess(source.numPages);
        }}
      >
        {numPages && <Page pageNumber={currentPage} />}
      </Document>

So yeah...appreciate if anyone could lend a helping hand here...

@github-actions
Copy link
Contributor

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.

@github-actions github-actions bot added the stale label Oct 24, 2022
@github-actions
Copy link
Contributor

This issue was closed because it has been stalled for 14 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed stale
Projects
None yet
Development

No branches or pull requests

5 participants