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

TypeError: Cannot set property 'workerSrc' of undefined #313

Closed
2 of 3 tasks
niteshshah04 opened this issue Dec 2, 2018 · 8 comments
Closed
2 of 3 tasks

TypeError: Cannot set property 'workerSrc' of undefined #313

niteshshah04 opened this issue Dec 2, 2018 · 8 comments
Labels
invalid This doesn't seem right question Further information is requested

Comments

@niteshshah04
Copy link

niteshshah04 commented Dec 2, 2018

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.

Describe what are you trying to achieve Ex. I'd like to display multiple pages of my PDF.

Describe solutions you've tried

Describe solutions you've already tried, if any. Make sure to include code samples if you're stuck on implementation.

Additional information

If applicable, add screenshots (preferably with browser console open) and files you have an issue with to help explain your problem.

Environment

  • Browser (if applicable) [e.g. Chrome 57, Firefox 59]:
  • React-PDF version [e.g. 3.0.4]:
  • React version [e.g. 16.3.0]:
  • Webpack version (if applicable) [e.g. 4.16.2]:
@niteshshah04
Copy link
Author

image

@moffsugita
Copy link

moffsugita commented Dec 3, 2018

It is ugly solution but I resolved like below.

import pdfMake from "pdfmake/build/pdfmake";
import pdfFonts from "pdfmake/build/vfs_fonts";
import { Document, Page, pdfjs } from 'react-pdf'
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`

@moffsugita
Copy link

npm install --save-dev pdfjs-dist

and

pdfjs.GlobalWorkerOptions.workerSrc = 'node_modules/pdfjs-dist/build/pdf.worker.js';

or
mozilla/pdf.js#8305

@niteshshah04
Copy link
Author

Thank You So Much for solution. Its working now.

@wojtekmaj
Copy link
Owner

wojtekmaj commented Dec 9, 2018

Can't help you since you completely ignored the form I created to help you describe the issue.

Also resolved in #291

@wojtekmaj wojtekmaj added the question Further information is requested label Dec 9, 2018
@wojtekmaj wojtekmaj changed the title While installing npm install react-pdf after run the code i am getting this issue "TypeError: Cannot set property 'workerSrc' of undefined" Could you please help me what is the issue.? TypeError: Cannot set property 'workerSrc' of undefined Dec 9, 2018
@wojtekmaj wojtekmaj added the invalid This doesn't seem right label Dec 9, 2018
@jp3492
Copy link

jp3492 commented Feb 4, 2019

I was having the same issues and following the suggestions in this issue im receiving a: InvalidPDFException {name: "InvalidPDFException", message: "Invalid PDF structure"} - error now.
If i use a url im getting a Cors issue.
Any suggestions? Im really struggeling to get this work in my React app (CRA, TypeScript)

@wojtekmaj
Copy link
Owner

@jp3492, this issue was exclusive to React-PDF 3.x. Try 4.x.

@charkhaniakash
Copy link

// It will work Now use this

import { pdfjs } from 'react-pdf';

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants