Repository navigation
Warning: Setting up fake worker. How to render PDF from ArrayBuffer using react-pdf in Next.js app? #1688
Replies: 8 comments 1 reply
|
I tried the copy "worker.min.js" to the public folder, but my However, then in the browser I get: So I need to perhaps compile it? What should I do now? |
|
Yea I am getting this same issue right now. My guess is it's something that Next.js did... |
|
I had a similar issue. Fix for me was using Next 13 instead of 14. |
|
bumping this issue- experiencing the same problem using Next 14 |
|
спасибо огромное всем! 2 дня искал решение проблемы, перешел на next 13 - все заработало |
|
I'm using Next 14.1.4 and 'react-pdf' 9.1.1, it works for me just using: This is how the Document component is setup:
Also, I added some config to the next.config.mjs as suggested in the docs (I'm not using turbopack, if you are, then follow the steps defined in the README): const nextConfig = {
+ swcMinify: false,
+ webpack: (config) => {
+ config.resolve.alias.canvas = false;
+ return config;
},
}; |
|
For anyone still hitting "Setting up fake worker" on recent versions: with react-pdf 10.x (pdfjs-dist 5.x) the worker file is pdfjs.GlobalWorkerOptions.workerSrc = new URL(
'pdfjs-dist/build/pdf.worker.min.mjs',
import.meta.url,
).toString()This lets the bundler resolve the pdfjs-dist version react-pdf actually installed, so the worker and the API version can't drift apart. Copying the worker into For an ArrayBuffer, pass Working example on Next.js 16 with an empty |

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I am getting these error messages in the chrome dev tools logs, when rendering the PDF
<Document>in my simple Next.js app:It looks like I need to setup the worker somehow? Did I miss that in the docs (looks like so)? I am successfully receiving an ArrayBuffer after doing
fetch(apiPath)to generate a PDF from LaTeX using thepdflatexCLI (and I have verified the PDF is renderable by checking the PDF manually), but it's not working. Here is my UI code:And here is my API route to generate the PDF, if that helps:
And the utility:
Any suggestions or ideas on why my PDF is not rendering now, and just saying this where the
<Document />was rendered?All reactions