Error during production build with pdfjs-dist. static/media/pdf.worker.min.05101219.mjs from Terser x 'import', and 'export' cannot be used outside of module code #61549
Replies: 7 comments 6 replies
-
|
yep I am also running into this. nrwl/nx#21611 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
For me downgrading to react-pdf 8.0.2 solved the issue. |
Beta Was this translation helpful? Give feedback.
-
|
Was pulling my hair out until I found the following steps. Finally got it working. |
Beta Was this translation helpful? Give feedback.
-
|
For me I don't want to downgrade the pdfjs-dist version as the pdfjs-dist version has high vulnerability in lower versions any other alternative ? |
Beta Was this translation helpful? Give feedback.
-
|
Try |
Beta Was this translation helpful? Give feedback.
-
|
For those who still have this issue, I had to do two things to fix this (I am on Next.js 12.2):
"react-pdf": "8.0.2"
import { Document, Page, pdfjs } from 'react-pdf';
// Method 1
pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.js', import.meta.url).toString();
// Method 2
// const workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.js`;
// pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;Be careful what worker file extension you use. For I think only newer versions of react-pdf support |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Getting these when trying to deploy a Next.js 14 app to Vercel on Node.js 20:
It appears to be coming from pdfjs-dist which I have added through
pnpm add pdfjs-dist. Everything works fine locally, I have been able to develop a webpage using pdfjs-dist, but not sure what could be the culprit here. Any ideas?Additional information
Example
I didn't add anything fancy to my next.config.ts, it is using what I had before:
Beta Was this translation helpful? Give feedback.
All reactions