wojtekmaj / react-pdf

Display PDFs in your React app as easily as if they were images.
https://projects.wojtekmaj.pl/react-pdf
MIT License
9.24k stars 877 forks source link

Cannot set properties of undefined (setting 'workerSrc') #1579

Closed stauersbol closed 1 year ago

stauersbol commented 1 year ago

Before you start - checklist

Description

The bug I'm encountered now is one that appeared after the ESM module compat and the latest release.

- error Error [TypeError]: Cannot set properties of undefined (setting 'workerSrc')
    at file:///home/stauersbol/Projects/dws-drawing-viewer/node_modules/react-pdf/dist/esm/index.js:11:37
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25) {
  digest: undefined
}

Steps to reproduce

  1. Setup a basic Next project and implement the recommended way of setting up react-pdf (In this case I'm using the unpkg.com for this, but I have same issue using the new URL way)
  2. Run next dev
  3. See the error when you load the site in your console

Expected behavior

Site loads properly and the PDF loads in.

Actual behavior

Next shows the error page with the error message.

Additional information

image This image should show the issue I'm facing.

image Same error in Browser Console.

Extra info: I'm using Next to run this. This is for a niche use case, due to the API.

How I setup workerSrc reference to the part where I mention unpkg: pdfjs.GlobalWorkerOptions.workerSrc =//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.js``

Environment

wojtekmaj commented 1 year ago

I just love dual ESM/CJS packages 🫠

Try v7.3.3, works for me!

stauersbol commented 1 year ago

I will give it a try tomorrow when I get it at work! Thank you for fixing it so fast @wojtekmaj!

stauersbol commented 1 year ago

Hey @wojtekmaj It is working as expected now, thank you for the quick fix!

wojtekmaj commented 1 year ago
image