react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

Failed to load PDF file : after version upgrade from 8.0.2 to 9.2.1

Open v-arasanga opened this issue 10 months ago • 10 comments

Before you start - checklist

  • [x] I followed instructions in documentation written for my React-PDF version
  • [x] I have checked if this bug is not already reported
  • [x] I have checked if an issue is not listed in Known issues
  • [x] If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo

Description

Upgraded react-pdf version from 8.0.2 to 9.2.1, issue : Failed to load PDF file

data passing Blob data (type: 'application/pdf')

PDF is displaying with the same code below(version 8.0.2), but after version upgrade(version 9.2.1) getting error.

Steps to reproduce

// entering into onDocumentLoadError and it is priniting "{}" private onDocumentLoadError = (error: Error): void => { if (!this.state.loadError) this.setState({ loadError: true }); this.LogService.LogError('PDFRenderer.onDocumentLoadError', JSON.stringify(error));

    console.log(JSON.stringify(error));
}; 

// Not entering into onLoadSuccess onLoadSuccess = ({ numPages }: any) => { console.log(numPages) this.setState({ pdfPageCount:numPages, });

  };

{this.props.ContractFile != null && ( <Document file={this.props.ContractFile} onLoadSuccess={this.onLoadSuccess} onLoadError={this.onDocumentLoadError} > { [...Array(pdfPageCount)].map((_, index) => (
<Page key={index} pageNumber={index + 1} /> ))}

                </Document>
            )}

this.props.ContractFile is a Blob data (type: 'application/pdf')

Expected behavior

Need to display the PDF

Actual behavior

Error : Failed to load PDF file.

Additional information

No response

Environment

  • Browser (if applicable): Chrome & Edge
  • React-PDF version: 9.2.1
  • React version:
  • Bundler name and version (if applicable):

v-arasanga avatar Mar 12 '25 11:03 v-arasanga

Any updates on this?

rahulmahajannn avatar Mar 24 '25 15:03 rahulmahajannn

@rahulmahajannn are you facing same issue ?

v-arasanga avatar Mar 25 '25 04:03 v-arasanga

I am also facing issue after upgrade from 8.0.2 to 9.2.1

next build

▲ Next.js 15.2.3

  • Environments: .env.production, .env

✓ Linting and checking validity of types Creating an optimized production build ... ✓ Compiled successfully Collecting page data .[TypeError: Promise.withResolvers is not a function]

Build error occurred

Windows Version 11 Node - v20.11.0| Next - v15.2.3

@wojtekmaj - Could you suggest if this can be fixed by just upgrading Node to higher versions >=22.0.0 ?

ravi3222 avatar Mar 27 '25 04:03 ravi3222

Yep, 22.11.0 and up should be fine according to node.green.

Or, load React-PDF dynamically on the client side only. It's not of much use on the server.

wojtekmaj avatar Mar 27 '25 06:03 wojtekmaj

@wojtekmaj , Any Update what is the issue in React. [Failed to load PDF file : after version upgrade from 8.0.2 to 9.2.1]

v-arasanga avatar Apr 01 '25 04:04 v-arasanga

Yeah, 22 works. Really starting to dislike next.

maxpowernz avatar Apr 06 '25 10:04 maxpowernz

@wojtekmaj Upgrading to Node 22.14.0 didn't fix it. I am using react router V7 in framework mode, with vite 6.2.5 The build react-router build doesn't throw any error, but when we try to open the pdf it doesn't work, and shows a msg that failed to load pdf file.

AyushJainSprinto avatar Apr 09 '25 12:04 AyushJainSprinto

@maxpowernz : Can you please share the steps you followed, that worked the React PDF running in Node 22.

rahulmahajannn avatar Apr 30 '25 12:04 rahulmahajannn

I'm just trying out this library in my react 19 project and I got the same issue, no way to load a PDF. I always get the Failed to load PDF file. No idea why. I'm looking for an alternative.

Ganbin avatar May 02 '25 13:05 Ganbin

Same here, been trying for over an hour to add it in my Vite app with the help of cursor, but it seems is very dependent on other libs and it requires weird configs.

muscaiu avatar May 22 '25 10:05 muscaiu

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.

github-actions[bot] avatar Aug 25 '25 00:08 github-actions[bot]

This issue was closed because it has been stalled for 14 days with no activity.

github-actions[bot] avatar Sep 08 '25 00:09 github-actions[bot]