Closed nike1v closed 3 weeks ago
What do you set workerSrc to?
I have tried the way with //unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs
and the recomended by you new URL...
The problem is TurboPack in my case, since without turbo it works as it should.
Also I do have some functional that I need to use, so I have some questions: Does your library is capable of working with forms? Extracting, prefilling with data. Does your library can work with Toolbar (pages, scale, search, document properties)? Does your library have flag for forms that will bake them READ-ONLY and block all fields? If no, I would like to contribute or I will have to do it myself. Thanks in advance!
+1 in version 9.00, before was working fine
import { Document, Page, pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
'pdfjs-dist/build/pdf.worker.min.mjs',
import.meta.url,
).toString();
Module not found: Can't resolve 'pdfjs-dist/build/pdf.worker.min.mjs'
+1 in version 9.00, before was working fine
import { Document, Page, pdfjs } from 'react-pdf'; pdfjs.GlobalWorkerOptions.workerSrc = new URL( 'pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url, ).toString();
Module not found: Can't resolve 'pdfjs-dist/build/pdf.worker.min.mjs'
Have you tried dev mode without TurboPack?
+1 in version 9.00, before was working fine
import { Document, Page, pdfjs } from 'react-pdf'; pdfjs.GlobalWorkerOptions.workerSrc = new URL( 'pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url, ).toString();
Module not found: Can't resolve 'pdfjs-dist/build/pdf.worker.min.mjs'
Have you tried dev mode without TurboPack?
I am not using turbopack
Ok, so remove node_modules clean yarn.lock file yarn install Works with 9.0.0, but before I did the same and didn't worked. I don't know ...
Ok, so remove node_modules clean yarn.lock file yarn install Works with 9.0.0, but before I did the same and didn't worked. I don't know ...
As you said, probably some cache issues, glad it worked.
Ok, so remove node_modules clean yarn.lock file yarn install Works with 9.0.0, but before I did the same and didn't worked. I don't know ...
As you said, probably some cache issues, glad it worked.
The build failing in GitHub Action and locally now, but next dev works Creating an optimized production build ... Failed to compile.
static/media/pdf.worker.min.9b170941.mjs from Terser
x 'import', and 'export' cannot be used outside of module code
,-[18:1]
18 | *
19 | * @licend The above is the entire license notice for the
20 | * JavaScript code in this page
Also it puts content of the file in to the terminal during the build
Ok, so remove node_modules clean yarn.lock file yarn install Works with 9.0.0, but before I did the same and didn't worked. I don't know ...
As you said, probably some cache issues, glad it worked.
The build failing in GitHub Action and locally now, but next dev works Creating an optimized production build ... Failed to compile.
static/media/pdf.worker.min.9b170941.mjs from Terser x 'import', and 'export' cannot be used outside of module code ,-[18:1] 18 | * 19 | * @licend The above is the entire license notice for the 20 | * JavaScript code in this page
Also it puts content of the file in to the terminal during the build
Try to use //unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs
this instead of new URL method. That helped me.
I have discovered that this issue persist only in case when component with pdfjs-dist or react-pdf have "use client" directive or any parent component have this. If whole chain is server components, than it works fine. Probably I should open an issue for PDF.JS itsef, because it looks like their problem.
Weird that I already provided the workerSrc at the most top page.tsx which is server component and even now my PDFViewer component throws this error when used with Turbopack. Probably this is why you suggested to set workerSrc only in client components.
swcMinify: false
.
- If you're using Turbo and see "Module not found" or "Failed to compile": Please kindly share your feedback with Next.js team and in the meantime try default Webpack mode instead.
- If you're not using Turbo and see "Module not found", ensure you don't have several copies of pdfjs-dist installed, remove node_modules and install your repo from scratch.
- If you see "'import', and 'export' cannot be used outside of module code": Please kindly share your feedback on using ESM workers with Next.js team and in the meantime try setting
swcMinify: false
.
Thanks for your reply! I indeed stick with using regular dev mode now without turbo. The issue is addressed to next.js (turbopack) team so they can fix it.
I had some questions for you about the library, if you have time, please answer them! Cheer!
Ok, so remove node_modules clean yarn.lock file yarn install Works with 9.0.0, but before I did the same and didn't worked. I don't know ...
As you said, probably some cache issues, glad it worked.
The build failing in GitHub Action and locally now, but next dev works Creating an optimized production build ... Failed to compile.
static/media/pdf.worker.min.9b170941.mjs from Terser x 'import', and 'export' cannot be used outside of module code ,-[18:1] 18 | * 19 | * @licend The above is the entire license notice for the 20 | * JavaScript code in this page
Also it puts content of the file in to the terminal during the build
Hello, it's confirmed for me too :
I can see this message using next build
with react pdf 9.0.0 (8.x was working)
static/media/pdf.worker.min.9b170941.mjs from Terser
x 'import', and 'export' cannot be used outside of module code
,-[18:1]
18 | *
19 | * @licend The above is the entire license notice for the
20 | * JavaScript code in this page
21 | */var e={d:(t,i)=>{for(var a in i)e.o(i,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:i[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},__webpack_exports__=globalThis.pdfjsWorker={};e.d(__webpack_exports__,{WorkerMessageHandler:()=>W
This snippet show that webpack is used (turbo pack in dev is working), Terser is used (and not swc minifier)
@titouancreach This has been recently fixed in https://github.com/vercel/next.js/pull/66817 and is waiting for the next release. In the meantime try setting swcMinify: false
.
The "from Terser" is another Next.js bug, it's NOT coming from Terser.
Here's the exact line in SWC where it's coming from :)
@wojtekmaj ohhhh, thanks for clarification !
Before you start - checklist
Description
I had used previous version of your library and though of using it as base for my needs since it doesn't cover all points that is required by my tasks. But since the update to 9.0.0 i do have this issue whenever I try to import anything from your library of pdfjs-dist. I know that this is not particularly your issue, but maybe you do know the solution for this.![image](https://github.com/wojtekmaj/react-pdf/assets/20584538/a5a89bd2-efb0-4b77-a4db-12a9c2cad01d)
Steps to reproduce
import anything from react-pdf or pdfjs-dist
Expected behavior
component loads without errors
Actual behavior
When pdfjs-dist is imported from react-pdf (or components that use pdfjs-dist) or even the pdfjs-dist is imported, the error occures:![image](https://github.com/wojtekmaj/react-pdf/assets/20584538/db75ce6e-8ba4-4c3c-9340-4389aed86d41)
Additional information
No response
Environment