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

Error since updating from version 7.2.0 to 7.3.0 in next js app #1578

Closed
wojtekmaj opened this issue Jul 31, 2023 Discussed in #1577 · 3 comments
Closed

Error since updating from version 7.2.0 to 7.3.0 in next js app #1578

wojtekmaj opened this issue Jul 31, 2023 Discussed in #1577 · 3 comments
Labels
bug Something isn't working

Comments

@wojtekmaj
Copy link
Owner

Discussed in #1577

Originally posted by benzler July 31, 2023
Since upgrading to the newest version I have the following error in my typescript next js app:

SyntaxError: Named export 'PDFDataRangeTransport' not found. The requested module 'pdfjs-dist' is a CommonJS module, which may not support all module.exports as named exports.

This is my code to show the pdf:


import { Document, Page, pdfjs } from 'react-pdf';
import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
import 'react-pdf/dist/esm/Page/TextLayer.css';


  useEffect(() => {
    if (typeof window !== 'undefined') {
      // https://stackoverflow.com/questions/65740268/create-react-app-how-to-copy-pdf-worker-js-file-from-pdfjs-dist-build-to-your
      pdfjs.GlobalWorkerOptions.workerSrc = new URL(
        'pdfjs-dist/build/pdf.worker.min.js',
        import.meta.url,
      ).toString();
    }
  }, []);

  const [numPages, setNumPages] = useState(null);
  const [pageNumber, setPageNumber] = useState(1);

  function onDocumentLoadSuccess({ numPages }: { numPages: number }) {
    setNumPages(numPages);
  }

 <Document
                      file={filePreview}
                      onLoadSuccess={onDocumentLoadSuccess}
                    >
                      <Page pageNumber={pageNumber} />
                    </Document>

Can please someone help me how to fix this error?

Before updating the code worked perfectly.

Seems like I'm not the only one having this issue: https://stackoverflow.com/questions/76796240/named-export-pdfdatarangetransport-not-found-while-using-react-pdf-in-next-js?newreg=704b67926da2412d96aa0144a5a69bd6

@wojtekmaj wojtekmaj added the bug Something isn't working label Jul 31, 2023
@wojtekmaj
Copy link
Owner Author

@benzler Can you provide a reproducible example? Just tried on a fresh Next.js app with no issues. Can't even figure out where this error is coming from.

@tacomanator
Copy link

Not sure if this is useful but I was able to reproduce this error in a project which uses the pages router only, no app router.

Was having same issue so created test project to reproduce but it worked fine in the new project. I couldn't find any obvious reason so I started copying over pieces of the existing project one-by-one, confirming along the way. Finally I had copied over everything and the new project still worked. The only difference was that the test project had an app folder where as the existing project does not use the app router at all. I deleted the app/ folder from the test project, reinstalled node modules, and the error appeared.

My conclusion is that the error appears when using the pages router only, but not when using the pages router in conjunction with the app router.

@wojtekmaj
Copy link
Owner Author

Very helpful actually! Let me try this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants