Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Setting up fake worker failed: "Cannot read properties of undefined (reading 'WorkerMessageHandler')".[Suggestion]: #6968

Closed
dineshpithiya-virtusa opened this issue Jun 19, 2024 · 1 comment

Comments

@dineshpithiya-virtusa
Copy link

Summary

Code working fine with yarn start
Code not working after yarn build Build also done successful without error but view pdf feature not working
After yarn build it return error like below with view pdf feature

Setting up fake worker failed: "Cannot read properties of undefined (reading 'WorkerMessageHandler')". and in console Warning: Setting up fake worker.
pdf.worker.min.49575ffd3eb84513c4b6.js:1 Uncaught ReferenceError: require is not defined
at pdf.worker.min

Below version I am using
Node js version = v21.0.0
Npm version = 10.2.0
"react": "^18.2.0"
"pdfjs-dist": "^3.11.174",
"@react-pdf-viewer/core": "^3.12.0",

Below is my code about display pdf
import { Worker, Viewer } from "@react-pdf-viewer/core";
import "@react-pdf-viewer/core/lib/styles/index.css";
import "@react-pdf-viewer/default-layout/lib/styles/index.css";
const workerUrl = new URL(
'pdfjs-dist/build/pdf.worker.min.js',
import.meta.url,
).toString();


Note:- This code working with build as well but suddenly stop working, seems due to version issue, but not able to figure it out

Page

No response

Details

Code working fine with yarn start
Code not working after yarn build Build also done successful without error but view pdf feature not working
After yarn build it return error like below with view pdf feature

Setting up fake worker failed: "Cannot read properties of undefined (reading 'WorkerMessageHandler')". and in console Warning: Setting up fake worker.
pdf.worker.min.49575ffd3eb84513c4b6.js:1 Uncaught ReferenceError: require is not defined
at pdf.worker.min

Below version I am using
Node js version = v21.0.0
Npm version = 10.2.0
"react": "^18.2.0"
"pdfjs-dist": "^3.11.174",
"@react-pdf-viewer/core": "^3.12.0",

Below is my code about display pdf
import { Worker, Viewer } from "@react-pdf-viewer/core";
import "@react-pdf-viewer/core/lib/styles/index.css";
import "@react-pdf-viewer/default-layout/lib/styles/index.css";
const workerUrl = new URL(
'pdfjs-dist/build/pdf.worker.min.js',
import.meta.url,
).toString();


Note:- This code working with build as well but suddenly stop working, seems due to version issue, but not able to figure it out

@harish-sethuraman
Copy link
Collaborator

This issue is not related to react/react documentation site but more related to JS/your code.

@harish-sethuraman harish-sethuraman closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants