iqbal-rashed / pdftoimg-js

A javascript library that help to convert pdf to img in both platform nodejs and frontend library/framework like React, Nextjs.
https://github.com/iqbal-rashed/pdftoimg-js
MIT License
3 stars 1 forks source link

nextjs error #1

Open sahanatvessel opened 2 months ago

sahanatvessel commented 2 months ago

Error processing file: Error: Setting up fake worker failed: "Cannot find module './pdf.worker.js' Require stack:

ntyped commented 4 weeks ago

Under Next.js@14.2.1 and pdf-dist@3.1.81: I copied the worker file from node_modules to the public folder (static assets). cp /node_modules/pdfjs-dist/legacy/build/pdf.worker.js /public/pdf.worker.js

And then for server side I explicitly defined the worker: pdfjsLib.GlobalWorkerOptions.workerSrc = process.cwd() + '/public/pdf.worker.js';

Turned out the absolute path with process.cwd() is important for the production build.