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
🌐
React PDF Viewer
react-pdf-viewer.dev › docs › basic-usage
Basic usage - React PDF Viewer
<Worker workerUrl="https://unpkg.com/[email protected]/build/pdf.worker.min.js"> <!-- The viewer component will be put here --> ... </Worker> It's up to you to use the `pdf.worker.min.js` file from popular services, such as · https://unpk...
🌐
Mozilla
mozilla.github.io › pdf.js › examples
PDF.js - Examples
PDF.js heavily relies on the use of Promises. If promises are new to you, it's recommended you become familiar with them before continuing on. This tutorial shows how PDF.js can be used as a library in a web browser.
🌐
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
PDF Reader in JavaScript - Simple. Fast. Reliable. Content delivery at its finest. cdnjs is a free and open-source CDN service trusted by over 12.5% of all websites, serving over 200 billion requests each month, powered by Cloudflare. We make it faster and easier to load library files on your ...
🌐
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. You have several options. ... import { pdfjs } from 'react-pdf'; pdfjs.GlobalWorkerOptions.workerSrc = new URL( 'pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url, ).toString();
Starred by 10.7K users
Forked by 981 users
Languages   TypeScript 94.3% | CSS 5.6% | HTML 0.1%
🌐
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 › pdf.js
GitHub - mozilla/pdf.js: PDF Reader in JavaScript
This will generate pdf.js and pdf.worker.js in the build/generic/build/ directory (respectively build/generic-legacy/build/). Both scripts are needed but only pdf.js needs to be included since pdf.worker.js will be loaded by pdf.js. The PDF.js files are large and should be minified for production.
Starred by 52.4K users
Forked by 10.5K users
Languages   JavaScript 71.3% | Fluent 25.5% | CSS 2.2%
🌐
Nutrient
nutrient.io › blog › sdk › how to build a javascript pdf viewer with pdfjs
JavaScript PDF viewer tutorial with PDF.js
November 4, 2024 - import { GlobalWorkerOptions } from 'https://cdn.jsdelivr.net/npm/[email protected]/build/pdf.min.mjs'; Set the workerSrc property on GlobalWorkerOptions to point to the worker script.
Find elsewhere
🌐
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 - Learn how to build a fast, customizable PDF viewer in React using PDF.js and Next.js. Includes full code examples, setup instructions, and a comparison with Nutrient’s feature-rich PDF SDK.
🌐
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
🌐
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/p...
🌐
ComPDF
compdf.com › blog › build-javascript-pdf-viewer-with-open-source-pdfjs
Build JavaScript PDF Viewer with PDF.js | ComPDFKit
Step 1: Get PDF.js · <script src="https://unpkg.com/[email protected]/build/pdf.min.mjs" type="module"></script> Step 2: Loading a PDF File and scale the PDF file. <script type="module"> // If absolute URL from the remote server is provided, ...
🌐
Snyk
snyk.io › advisor › pdfjs-dist › functions › pdfjs-dist.globalworkeroptions
How to use the pdfjs-dist.GlobalWorkerOptions function in pdfjs-dist | Snyk
import * as React from "react"; import * as CSSModules from "react-css-modules"; import * as styles from "./index.less"; import * as pdfjsLib from "pdfjs-dist"; const pdfjsViewer = require("../../../node_modules/pdfjs-dist/web/pdf_viewer.js"); // The workerSrc property shall be specified. pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.0.550/pdf.worker.js"; // default scale const DEFAULT_MIN_SCALE = 0.25; const DEFAULT_MAX_SCALE = 10.0; let USE_ONLY_CSS_ZOOM = true; let TEXT_LAYER_MODE = 0; // DISABLE let MAX_IMAGE_SIZE = 1024 * 1024; let CMAP_PACKED = true; let DEFAULT_URL = "/test.pdf"; let DEFAULT_SCALE_DELTA = 1.1; let MIN_SCALE = DEFAULT_MIN_SCALE; let MAX_SCALE = DEFAULT_MAX_SCALE; let DEFAULT_SCALE_VALUE: string|number = "auto"; // in order to be responsive interface IProps { url: string|object; page?: number|string; scale?: number|string;
🌐
React PDF Viewer
react-pdf-viewer.dev › examples › keep-the-worker-version-in-sync-with-pdfjs-dist-version
Keep the worker version in sync with pdfjs-dist version - React PDF Viewer
import packageJson from '../package.json'; const pdfjsVersion = packageJson.dependencies['pdfjs-dist']; <Worker workerUrl={`https://unpkg.com/pdfjs-dist@${pdfjsVersion}/build/pdf.worker.min.js`}>...</Worker>; Compile and set the worker source with Webpack
🌐
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
gist.github.com › Katerinka28 › 09f3496710c2dac7b3fe3335ae4d81a0
pdf.worker.js · GitHub
Clone this repository at &lt;script src=&quot;https://gist.github.com/Katerinka28/09f3496710c2dac7b3fe3335ae4d81a0.js&quot;&gt;&lt;/script&gt; Save Katerinka28/09f3496710c2dac7b3fe3335ae4d81a0 to your computer and use it in GitHub Desktop. Download ZIP · pdf.worker.js ·
🌐
Nutrient
nutrient.io › blog › sdk › implement pdf viewer pdf js
PDF.js viewer example: Implement a simple PDF viewer with PDF.js
October 17, 2024 - This HTML file includes the basic ... pdf.min.mjs to include PDF.js. First, we import the pdfjsLib from a CDN and set the worker script to handle rendering PDF files in the background....