Warning: UnknownErrorException: Cannot read properties of undefined (reading 'getReader')
shamsanjay156 opened this issue · comments
sham sanjay commented
Before you start - checklist
- I followed instructions in documentation written for my React-PDF version
- I have checked if this bug is not already reported
- I have checked if an issue is not listed in Known issues
- If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo
Description
Hi guys,
I have tried to display my local pdf in a react + vite application but im getting the below error, I dont know the solution could anybody help me with this.
Warning: UnknownErrorException: Cannot read properties of undefined (reading 'getReader')
Steps to reproduce
import { useEffect, useState } from 'react'
import { Document, Page, pdfjs } from 'react-pdf'
import pdf from '../../assets/pdf/UAEPASS_Buttons.pdf'
export const PdfComponent = () => {
const [numPages, setNumPages] = useState<number>()
const [pageNumber, setPageNumber] = useState<number>(1)
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
'pdfjs-dist/build/pdf.worker.min.js',
import.meta.url
).toString()
function onDocumentLoadSuccess({ numPages }: { numPages: number }): void {
setNumPages(numPages)
}
return (
<div>
<Document file={pdf} onLoadSuccess={onDocumentLoadSuccess}>
<Page pageNumber={pageNumber} />
</Document>
<p>
Page {pageNumber} of {numPages}
</p>
</div>
)
}
Expected behavior
pdf need to be displayed
Actual behavior
console.js:213 Warning: UnknownErrorException: Cannot read properties of undefined (reading 'getReader')
at Document2 (http://localhost:5173/node_modules/.vite/deps/react-pdf.js?v=f727c0b1:19295:9)
at div
Additional information
No response
Environment
- Browser (if applicable):
- React-PDF version:
- React version:
- Webpack version (if applicable):