Install pdfjs-dist

import { Document, Page, pdfjs } from "react-pdf";
import pdfjsWorker from "pdfjs-dist/build/pdf.worker.entry";

pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;

Reference: https://github.com/mozilla/pdf.js/issues/8305

UPDATE

react-pdf >= 9.0.0

import { Document, Page, pdfjs } from "react-pdf";
import { WorkerMessageHandler } from "pdfjs-dist/build/pdf.worker.min.mjs";

pdfjs.GlobalWorkerOptions.workerSrc = new URL(
  WorkerMessageHandler,
  import.meta.url
).toString();

This also fixed a known issue:

Failed to load module script: Expected a JavaScript-or-Wasm module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec.

https://github.com/wojtekmaj/react-pdf/issues/1825

Answer from lissettdm on Stack Overflow
🌐
Mozilla
mozilla.github.io › pdf.js › examples
PDF.js - Examples
Remember though that PDF.js uses promises, and the above will return a PDFDocumentLoadingTask instance that has a promise property which is resolved with the document object.
🌐
Mozilla
mozilla.github.io › pdf.js › getting_started
PDF.js - Getting Started
├── docs/ - website source ... dependency versions └── package.json - package definition and dependencies · With the prebuilt or source version, open web/viewer.html in a browser and the test pdf should load. Note: the worker is not enabled for file:// urls, so use ...
🌐
Reddit
reddit.com › r/nextjs › how do i solve this issue: error: setting up fake worker failed: "cannot find module '/pdf.worker.js' ?
r/nextjs on Reddit: How do I solve this issue: Error: Setting up fake worker failed: "Cannot find module '/pdf.worker.js' ?
August 3, 2023 - React-pdf uses under the hood pdfjs, and you should follow their configuration instructions in order to properly make it work for Next.js: import { pdfjs } from 'react-pdf'; pdfjs.GlobalWorkerOptions.workerSrc = new URL( 'pdfjs-dist/build/pdf.worker.min.js', import.meta.url, ).toString();
🌐
React PDF Viewer
react-pdf-viewer.dev › docs › basic-usage
Basic usage - React PDF Viewer
https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.worker.min.js · or download and store it on your server. Note · It's very important to note that the worker version and the `pdfjs` package (mentioned in the Install pdfjs library section of Getting started) have to be the same.
🌐
npm
npmjs.com › package › pdfjs-dist
pdfjs-dist - npm
Generic build of Mozilla's PDF.js library.. Latest version: 5.4.449, last published: 12 days ago. Start using pdfjs-dist in your project by running `npm i pdfjs-dist`. There are 2279 other projects in the npm registry using pdfjs-dist.
      » npm install pdfjs-dist
    
Published   Nov 29, 2025
Version   5.4.449
🌐
GitHub
github.com › mozilla › pdfjs-dist › blob › master › build › pdf.worker.js.map
pdfjs-dist/build/pdf.worker.js.map at master · mozilla/pdfjs-dist
Generic build of PDF.js library. . Contribute to mozilla/pdfjs-dist development by creating an account on GitHub.
Author   mozilla
🌐
GitHub
github.com › mozilla › pdf.js
GitHub - mozilla/pdf.js: PDF Reader in JavaScript
PDF Reader in JavaScript. Contribute to mozilla/pdf.js development by creating an account on GitHub.
Starred by 52.4K users
Forked by 10.5K users
Languages   JavaScript 71.3% | Fluent 25.5% | CSS 2.2%
🌐
GitHub
github.com › mozilla › pdf.js › issues › 8305
What should be the value for `workerSrc`? · Issue #8305 · mozilla/pdf.js
March 13, 2017 - a Node require spec that'll get resolved and bundled into the same file via webpack & node? e.g. PDFJS.workerSrc = 'pdfjs-dist/build/pdf.worker.js';
Published   Apr 17, 2017
Find elsewhere
🌐
GitHub
github.com › wojtekmaj › react-pdf
GitHub - wojtekmaj/react-pdf: Display PDFs in your React app as easily as if they were images.
For React-PDF to work, PDF.js worker needs to be provided.
Starred by 10.7K users
Forked by 981 users
Languages   TypeScript 94.3% | CSS 5.6% | HTML 0.1%
🌐
npm
npmjs.com › package › react-pdf-js-worker
react-pdf-js-worker - npm
A React component to wrap PDF.js. Latest version: 2.0.0, last published: 9 years ago. Start using react-pdf-js-worker in your project by running `npm i react-pdf-js-worker`. There are no other projects in the npm registry using react-pdf-js-worker.
      » npm install react-pdf-js-worker
    
Published   Aug 29, 2016
Version   2.0.0
Author   Mike Cousins
🌐
Snyk
snyk.io › advisor › pdfjs-dist › functions › pdfjs-dist.globalworkeroptions
How to use the pdfjs-dist.GlobalWorkerOptions function in pdfjs-dist | Snyk
async function createPDFViewer() { PDFJS.GlobalWorkerOptions.workerSrc = '../../../node_modules/pdfjs-dist/build/pdf.worker.js'; const container = document.getElementById('viewerContainer'); if (! container) { throw new Error("No container"); } const pdfLinkService = new PDFLinkService(); // the text area is working!
🌐
jsDelivr
jsdelivr.com › package › npm › pdf.worker
pdf.worker CDN by jsDelivr - A CDN for npm and GitHub
October 10, 2023 - A free, fast, and reliable CDN for pdf.worker. This is a required file for pdf js to work
Published   Oct 10, 2023
🌐
Google Groups
groups.google.com › g › mozilla.dev.pdf-js › c › 8B6iCsj5Hkg
pdf.worker.js and other js files make for a large client download
3. Configure HTTP server to support caching and compression. The pdf.js (which is smaller one) is only needed for initial loading, pdf.worker.js is loaded when document is about to be loaded. So UI/web page will be loaded faster to give user some control/information.
🌐
GitHub
github.com › mozilla › pdf.js › issues › 10813
2019 Recommended way to use pdf.worker.js with create-react-app · Issue #10813 · mozilla/pdf.js
March 19, 2019 - I've had problems that many had regarding using pdf.worker.js inside my react application (I build a wrapper on pdf.js for react). I'm using Create React App, I tried many things from hosting from cloud: PdfJsLib.GlobalWorkerOptions.workerSrc = PDFJS_WORKER_CLOUD_URL; this works but I must make it work locally.
Published   May 13, 2019
🌐
cdnjs
cdnjs.com › home › libraries › pdf.js › 2.6.347
pdf.js - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers
https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.6.347/pdf.worker.min.js · https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.6.347/pdf_viewer.css · https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.6.347/pdf_viewer.js · https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.6.347/pdf_viewer.js.map ·
🌐
Nutrient
nutrient.io › blog › sdk › how to build a reactjs viewer with pdfjs
Build a React PDF viewer with PDF.js and Next.js: Step-by-step tutorial
July 16, 2025 - PDF.js uses web workers to offload the parsing and rendering of PDFs to a background thread, improving performance. To keep the setup simple, manually copy the worker script to the public directory, which is served statically by Next.js.
🌐
Observable
observablehq.com › @hastebrot › how-pdfjs-loads-its-worker-source
how pdfjs loads its worker source / Benjamin | Observable
April 27, 2020 - Build files can be found at https://github.com/mozilla/pdfjs-dist/tree/v2.4.456/build and https://unpkg.com/browse/[email protected]/build/. Example files can be found at https://github.com/mozilla/pdf.js/tree/v2.4.456/examples
🌐
GitHub
github.com › wojtekmaj › react-pdf › issues › 1855
Can't resolve 'pdfjs-dist/build/pdf.worker.min.mjs in Nextjs 14 app router · Issue #1855 · wojtekmaj/react-pdf
August 13, 2024 - If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo · import { Box, CircularProgress, Pagination, Stack, Typography } from '@mui/material'; import React, { useState } from 'react'; import { DocumentText } from 'iconsax-react'; import 'react-pdf/dist/esm/Page/AnnotationLayer.css'; import 'react-pdf/dist/esm/Page/TextLayer.css'; import { Document, Page, pdfjs } from 'react-pdf'; pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url).toString(); const options = { cMapUrl: '/cmaps/', standardFontDataUrl: '/stan
Published   Aug 13, 2024
🌐
Skool
skool.com › universityofcode › solved-pdfjs-worker-optiosn-url-issue
SOLVED pdfjs worker optiosn url issue · University of Code
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.js`;