wojtekmaj / react-pdf

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

Warning: UnknownErrorException: Cannot read properties of undefined (reading 'getReader') #1749

Open shamsanjay156 opened 3 months ago

shamsanjay156 commented 3 months ago

Before you start - checklist

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

github-actions[bot] commented 4 days ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.