Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Nextjs 14 - Module not found workerSrc #1918

Open
4 tasks done
agamm opened this issue Nov 23, 2024 · 2 comments
Open
4 tasks done

Nextjs 14 - Module not found workerSrc #1918

agamm opened this issue Nov 23, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@agamm
Copy link

agamm commented Nov 23, 2024

Before you start - checklist

  • I followed instructions in documentation written for my React-PDF version
  • I have checked if this bug is not already reported
  • I have checked if an issue is not listed in Known issues
  • If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo

Description

My code:

"use client";

import React, { useEffect } from "react";
import { Document, pdfjs } from "react-pdf";

pdfjs.GlobalWorkerOptions.workerSrc = "/pdf.worker.mjs";
export default function PDFTest() {

	return (
		<div>
			<Document file="https://arxiv.org/pdf/2304.14211" />
		</div>
	);
}

Steps to reproduce

  1. pnpm i react-pdf
  2. Downloaded the worker code to ./public

Expected behavior

PDF view works

Actual behavior

./node_modules/.pnpm/pdfjs-dist@4.4.168/node_modules/pdfjs-dist/build/pdf.mjs:11881:28

Module not found
  11879 |         return this.#mainThreadWorkerMessageHandler;
  11880 |       }
> 11881 |       const worker = await import( /*webpackIgnore: true*/this.workerSrc);
        |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  11882 |       return worker.WorkerMessageHandler;
  11883 |     };

Additional information

I tried deleting .next but that didn't help either.

Environment

  • Browser (if applicable): FF
  • React-PDF version: 9.1.1
  • React version: 18.3.1
  • Bundler name and version (if applicable): Nextjs 14.2.15 + next dev --turbo
@agamm agamm added the bug Something isn't working label Nov 23, 2024
@ayoubbyr
Copy link

ayoubbyr commented Dec 6, 2024

I had an issue while importning the worker. Here's what I did.

pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/legacy/build/pdf.worker.min.mjs`;

I guess you could just download that file and put it in the public folder. Should fix it

@agamm
Copy link
Author

agamm commented Dec 7, 2024

I had an issue while importning the worker. Here's what I did.

pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/legacy/build/pdf.worker.min.mjs`;

I guess you could just download that file and put it in the public folder. Should fix it

I also added it manually, but I hope it could be fixed here

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants