React-pdf: "Cannot read property 'WorkerMessageHandler' of undefined"

Created on 27 Aug 2020  路  2Comments  路  Source: wojtekmaj/react-pdf

Hi everyone,
Currently trying to use this library to display a PDF from a URL such as this: https://firebasestorage.googleapis.com/v0/b/feeval-dev.appspot.com/o/content%2FLm5qhy9aOTIpbXtPuwTL%2FGQnpqX9voRiQYuiAAJqT%2F1EZS6tyrnqYQHDlCHTiA?alt=media&token=7106aa73-8b49-4ca7-9d98-f5936d22c9b7

This is a file stored in a 'Storage Bucket' on Google's Firebase platform.

When trying to load an image in, I get a number of errors/warning showing the console in this order:

Warning: Setting up fake worker. (pdf.js:549)
Uncaught SyntaxError: Unexpected token '<' (pdf.worker.js:1)
Error: Setting up fake worker failed: "Cannot read property 'WorkerMessageHandler' of undefined". (pdf.js:11210)

Just wondering if this might be because I'm loading the PDF through a URL maybe?

Currently on react-pdf version 4.2.0

Most helpful comment

Solved by importing the correct entry point, as shown in the sample folder.

My import statement looked like this:
import { Document, Page } from 'react-pdf';

When because i'm using webpack, it needed this instead:
import { Document, Page } from 'react-pdf/dist/entry.webpack';

All 2 comments

Solved by importing the correct entry point, as shown in the sample folder.

My import statement looked like this:
import { Document, Page } from 'react-pdf';

When because i'm using webpack, it needed this instead:
import { Document, Page } from 'react-pdf/dist/entry.webpack';

Solved by importing the correct entry point, as shown in the sample folder.

My import statement looked like this:
import { Document, Page } from 'react-pdf';

When because i'm using webpack, it needed this instead:
import { Document, Page } from 'react-pdf/dist/entry.webpack';

For me it works when I use this import as stated in the README file:
import { Document } from 'react-pdf/dist/esm/entry.webpack';

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shivekkhurana picture shivekkhurana  路  4Comments

varand-pez picture varand-pez  路  3Comments

Vanals picture Vanals  路  4Comments

lorenzos picture lorenzos  路  5Comments

herneli picture herneli  路  3Comments