-
-
Notifications
You must be signed in to change notification settings - Fork 958
Description
Before you start - checklist
- I have read documentation in README
- I have checked sample and test suites to see real life basic implementation
- I have checked if this question is not already asked
What are you trying to achieve? Please describe.
I would like to setup the pdf worker on an un-ejected create-react-app application
Describe solutions you've tried
First I tried using the instructions on Browserify and Others. This would give me the error in the title: Uncaught TypeError: Cannot read property 'GlobalWorkerOptions' of undefined
.
import { pdfjs } from 'react-pdf'
pdfjs.GlobalWorkerOptions.workerSrc = process.env.PUBLIC_URL + '/pdf.worker.js'
Then I tried importing pdfjs directly from pdfjs-dist
, which got me: Uncaught TypeError: Cannot set property 'workerSrc' of undefined
import pdfjs from 'pdfjs-dist'
pdfjs.GlobalWorkerOptions.workerSrc = process.env.PUBLIC_URL + '/pdf.worker.js'
Since both these options did not work, I tried following this comment, as such I got no errors, but the warnings below:
window.PDFJS.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.0.305/pdf.worker.js'
warning:
./node_modules/pdfjs-dist/lib/display/api.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
And as a matter of fact I don't even know if it worked (how can I check if there is a worker running?)
Environment
- Browser : Chrome Version 70.0.3538.67
- React-PDF version 3.0.5
- React version 16.5.2
- Webpack version 4.19.1
- CRA version 1.5.2
Thanks for any tips and pointers!