diff --git a/src/components/SignatureFieldPlacer.tsx b/src/components/SignatureFieldPlacer.tsx index 7545437..3cf84d3 100644 --- a/src/components/SignatureFieldPlacer.tsx +++ b/src/components/SignatureFieldPlacer.tsx @@ -5,12 +5,12 @@ import { Badge } from "@/components/ui/badge"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { ChevronLeft, ChevronRight, X, Pen, Calendar as CalIcon, User as UserIcon } from "lucide-react"; import { cn } from "@/lib/utils"; +import pdfWorkerUrl from "pdfjs-dist/build/pdf.worker.min.mjs?url"; -// Use the bundled worker -pdfjs.GlobalWorkerOptions.workerSrc = new URL( - "pdfjs-dist/build/pdf.worker.min.mjs", - import.meta.url -).toString(); +// Use the bundled worker. The `?url` import lets Vite emit the worker as a +// hashed asset and return its real URL; `new URL("pdfjs-dist/...", import.meta.url)` +// does NOT resolve bare node_modules specifiers and 404s in production. +pdfjs.GlobalWorkerOptions.workerSrc = pdfWorkerUrl; export interface PlacedField { id: string; diff --git a/src/pages/PublicSignPage.tsx b/src/pages/PublicSignPage.tsx index bdaae99..1731b53 100644 --- a/src/pages/PublicSignPage.tsx +++ b/src/pages/PublicSignPage.tsx @@ -8,11 +8,12 @@ import { useToast } from "@/hooks/use-toast"; import { FileSignature, CheckCircle2, Loader2, Download, Ban, ChevronLeft, ChevronRight } from "lucide-react"; import SignaturePad from "@/components/SignaturePad"; import { format } from "date-fns"; +import pdfWorkerUrl from "pdfjs-dist/build/pdf.worker.min.mjs?url"; -pdfjs.GlobalWorkerOptions.workerSrc = new URL( - "pdfjs-dist/build/pdf.worker.min.mjs", - import.meta.url -).toString(); +// Vite emits the worker as a hashed asset and returns its real URL. The prior +// `new URL("pdfjs-dist/...", import.meta.url)` does not resolve a bare +// node_modules specifier and 404s in production, so the PDF never renders. +pdfjs.GlobalWorkerOptions.workerSrc = pdfWorkerUrl; interface Field { id: string;