wojtekmaj / react-pdf

Display PDFs in your React app as easily as if they were images.

Home Page:https://projects.wojtekmaj.pl/react-pdf

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: Failed to fetch.

promotion-xu opened this issue · comments

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

"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

  • Browser (if applicable):
  • React-PDF version: 6.0.0
  • React version: 16.14.0
  • Webpack version (if applicable):

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.