Skip to content

Commit

Permalink
docs: update readme for new pdf version (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
thucpn authored Jul 24, 2024
1 parent eee7d8c commit 9943a32
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,42 @@ function App() {
</PdfFocusProvider>
```

## Next.js

NextJs applications may need to update their configuration to be compatible with react-pdf v9 and pdfjs v4
If you have issues related to canvas, you can add the following to your `next.config.js`:

```diff
module.exports = {
+ webpack: (config) => {
+ config.resolve.alias.canvas = false;

+ return config;
+ },
}
```

Another common issue is: `TypeError: Promise.withResolvers is not a function`
To fix this issue, you need to use dynamic imports for the PDF component (to indicate to NextJs to use it for client-side rendering only).

```diff
- import { PDFViewer, PdfFocusProvider } from "@llamaindex/pdf-viewer";

+ import dynamic from "next/dynamic";

+ // Dynamic imports for client-side rendering only
+ const PDFViewer = dynamic(
+ () => import("@llamaindex/pdf-viewer").then((module) => module.PDFViewer),
+ { ssr: false },
+ );

+ const PdfFocusProvider = dynamic(
+ () =>
+ import("@llamaindex/pdf-viewer").then((module) => module.PdfFocusProvider),
+ { ssr: false },
+ );
```

## 🙏 Thanks

Thanks to the developers of the following dependencies that we're using:
Expand Down

0 comments on commit 9943a32

Please sign in to comment.