wojtekmaj / react-pdf

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

TypeError: Failed to fetch. #1762

Closed promotion-xu closed 2 months ago

promotion-xu commented 2 months ago

Before you start - checklist

Description

"pdfjs-dist": "^2.16.105",
"react-pdf": "^6.0.0",

import { Document, Page } from 'react-pdf/dist/esm/entry.webpack'
import { pdfjs } from 'react-pdf'
import 'react-pdf/dist/esm/Page/TextLayer.css'
import 'react-pdf/dist/esm/Page/AnnotationLayer.css'

pdfjs.GlobalWorkerOptions.workerSrc = `https://cdn/xxxxxxxxxx/2.16.105_pdf.worker.min.js`

<Document
      file={path}
      onLoadError={err => console.log('loadError',err)}
      onLoadSuccess={onDocumentLoadSuccess}
      loading={<Spinner size={64} sx={{ position: 'absolute', top: '50%', transform: 'translateY(-50%)' }} />}
      noData={<ErrorPage />}
    >
      {totalPageAry.map((ele) => (
        <Page key={`pdf${ele}`} pageNumber={ele} />
      ))}
    </Document>

page show:

image

console show:

image

network show:

image

Hi, team

I load the worker.js correctly, but it still load pdf failed. I am so strange , anyone can help me

Steps to reproduce

  1. install react-pdf@^6.0.0
  2. install pdfjs-dist@^2.16.105
  3. import and use

Expected behavior

expected load pdf correctly

Actual behavior

load pdf failed

Additional information

No response

Environment

wojtekmaj commented 2 months ago

Where in the documentation was to install a specific pdfjs-dist version on your own? This is likely what broke it.

Please follow the documentation closely.