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

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

Open
3 of 4 tasks
shamsanjay156 opened this issue Mar 26, 2024 · 0 comments
Open
3 of 4 tasks
Labels
bug Something isn't working

Comments

@shamsanjay156
Copy link

shamsanjay156 commented Mar 26, 2024

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):
@shamsanjay156 shamsanjay156 added the bug Something isn't working label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant