Skip to content

Commit 7f44a67

Browse files
[FIX] Fix PDF.js worker require is not defined error in staging (#1717)
1 parent ab906b3 commit 7f44a67

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

frontend/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
# production
1212
/build
1313

14+
# pdfjs worker file (copied from node_modules via postinstall)
15+
/public/pdf.worker.min.js
16+
1417
# misc
1518
.DS_Store
1619
.env.local

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"zustand": "^4.3.8"
5858
},
5959
"scripts": {
60+
"postinstall": "cp node_modules/pdfjs-dist/build/pdf.worker.min.js public/pdf.worker.min.js",
6061
"start": "react-scripts start",
6162
"build": "react-scripts build",
6263
"test": "react-scripts test",
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// Webpack 5 / Vite compatible asset module
2-
// Works with both CRA (Webpack) and Vite bundlers
3-
export const PDF_WORKER_URL = new URL(
4-
"pdfjs-dist/build/pdf.worker.min.js",
5-
import.meta.url
6-
).toString();
1+
// Use the worker file from the public folder (served as static asset)
2+
// This avoids Webpack processing which incorrectly bundles it with require() statements
3+
// Note: The ?url import suffix only works in Vite, not in CRA (Webpack)
4+
export const PDF_WORKER_URL = "/pdf.worker.min.js";

0 commit comments

Comments
 (0)