The problem here is that the version of React your project is using (^18.2.0) is not compatible with the react-to-pdf package's definition, which requires react version ^16.5.2 to be installed. At first glance, this may seem like an invalid error: the package expects a version higher than 16.5.2, and you've installed something above 18.2.0. However, any major version bump will create an incompatible state. We can understand this explicitly by reading npm's documentation on this topic, which states the following:

Assuming the host complies with semver, only changes in the host package's major version will break your plugin. Thus, if you've worked with every 1.x version of the host package, use "^1.0" or "1.x" to express this. If you depend on features introduced in 1.5.2, use "^1.5.2".

Armed with all of that knowledge, we now have handful of options for resolving this issue:

  1. Force install the plugin or use the legacy peer dependencies option, either of which provides no guarantee that this package works with your version of react.
  2. Downgrade react (this is technically an option, but don't do it).
  3. Find a more up-to-date alternative that accomplishes the same goal and is compatible with your version of react.

Additionally, if you really like this package, I would recommend opening up an issue on the maintainer's repository to ask for an update that tests compatibility with newer versions and publishes a new version of their own package.

Finally, I would recommend becoming familiar with this kind of error message and read through some of the official documentation on npm's website because this kind of thing is fairly common and understanding the basics will save you many future headaches.

Answer from Wes Harper on Stack Overflow
🌐
npm
npmjs.com › package › react-pdf
react-pdf - npm
October 9, 2025 - Latest version: 10.2.0, last published: 2 months ago. Start using react-pdf in your project by running `npm i react-pdf`. There are 985 other projects in the npm registry using react-pdf.
      » npm install react-pdf
    
Published   Oct 09, 2025
Version   10.2.0
Author   Wojciech Maj
🌐
npm
npmjs.com › package › react-to-pdf
react-to-pdf - npm
2 weeks ago - Create PDF documents from React Components. Latest version: 2.0.3, last published: 15 days ago. Start using react-to-pdf in your project by running `npm i react-to-pdf`. There are 28 other projects in the npm registry using react-to-pdf.
      » npm install react-to-pdf
    
Published   Nov 25, 2025
Version   2.0.3
Author   Marcos Andrei Ivanechtchuk
Discussions

reactjs - I can't install the react-to-pdf npm package - Stack Overflow
I have already tried this "npm cache clean --force". If you know another way of implementing a feature that allows users to download the webpage as a pdf, please let me know how. This is ... More on stackoverflow.com
🌐 stackoverflow.com
How to generate PDFs in react?
Why not have your backend build the pdf instead? More on reddit.com
🌐 r/reactjs
96
65
May 15, 2023
Best library for showing a pdf in react
If you don't need direct control over the PDF in any way, then just use an IFrame. It'll make the browser use their default viewer, which is generally a pretty decent one. There's also one made by Mozilla ( PDF.js ), but any PDF viewer is going to be pretty heavy in terms of code size. More on reddit.com
🌐 r/reactjs
24
33
December 2, 2022
How to Generate PDFs with NodeJS and React PDF
Hey everyone, A while back I posted about project I built with my colleagues that took the pain out of creating PDFs for apps. I promised people that I would follow up with a how-to guide on rolling your own backend system. Let me know if you have any questions! More on reddit.com
🌐 r/javascript
1
14
August 6, 2021
🌐
React-pdf
react-pdf.org
React-pdf
React renderer for creating PDF files on the browser and server
🌐
npm
npmjs.com › package › react-pdf-html
react-pdf-html - npm
November 9, 2025 - Html component for react-pdf with CSS support. Latest version: 2.1.4, last published: 12 days ago. Start using react-pdf-html in your project by running `npm i react-pdf-html`. There are 22 other projects in the npm registry using react-pdf-html.
      » npm install react-pdf-html
    
Published   Nov 09, 2025
Version   2.1.4
Author   Dan Blaisdell [email protected]
🌐
npm
npmjs.com › search
react pdf - npm search
A react-pdf-viewer component for React and Next.js.
🌐
React PDF Viewer
react-pdf-viewer.dev › docs › getting-started
Getting started - React PDF Viewer
React PDF Viewer uses the APIs provided by the popular pdfjs library. Execute the following command from the root folder to install pdfjs: npm install [email protected].120 ·
Find elsewhere
🌐
GitHub
github.com › javascriptiscoolpl › npm-simple-react-pdf
GitHub - javascriptiscoolpl/npm-simple-react-pdf: Simple PDF React component with vertical scroll bar (pdfjs-dist & ES6 syntax & Babel & Browserify).
Simple PDF React component with vertical scroll bar (pdfjs-dist & ES6 syntax & Babel & Browserify). - javascriptiscoolpl/npm-simple-react-pdf
Starred by 18 users
Forked by 18 users
Languages   JavaScript
🌐
npm
npmjs.com › package › react-native-pdf
react-native-pdf - npm
October 16, 2025 - Latest version: 7.0.3, last published: 2 months ago. Start using react-native-pdf in your project by running `npm i react-native-pdf`. There are 44 other projects in the npm registry using react-native-pdf.
      » npm install react-native-pdf
    
Published   Oct 16, 2025
Version   7.0.3
Author   Wonday
🌐
Nutrient
nutrient.io › blog › sdk › how to build a reactjs pdf viewer with react pdf
React PDF viewer: Complete guide to building with react-pdf in 2025
August 12, 2025 - To create a React PDF viewer with react-pdf: 1) Install the library (npm install react-pdf), 2) Import Document and Page components, 3) Configure the PDF.js worker, and 4) Build your own UI controls.
Top answer
1 of 2
1

The problem here is that the version of React your project is using (^18.2.0) is not compatible with the react-to-pdf package's definition, which requires react version ^16.5.2 to be installed. At first glance, this may seem like an invalid error: the package expects a version higher than 16.5.2, and you've installed something above 18.2.0. However, any major version bump will create an incompatible state. We can understand this explicitly by reading npm's documentation on this topic, which states the following:

Assuming the host complies with semver, only changes in the host package's major version will break your plugin. Thus, if you've worked with every 1.x version of the host package, use "^1.0" or "1.x" to express this. If you depend on features introduced in 1.5.2, use "^1.5.2".

Armed with all of that knowledge, we now have handful of options for resolving this issue:

  1. Force install the plugin or use the legacy peer dependencies option, either of which provides no guarantee that this package works with your version of react.
  2. Downgrade react (this is technically an option, but don't do it).
  3. Find a more up-to-date alternative that accomplishes the same goal and is compatible with your version of react.

Additionally, if you really like this package, I would recommend opening up an issue on the maintainer's repository to ask for an update that tests compatibility with newer versions and publishes a new version of their own package.

Finally, I would recommend becoming familiar with this kind of error message and read through some of the official documentation on npm's website because this kind of thing is fairly common and understanding the basics will save you many future headaches.

2 of 2
0

Try :

  • npm install react-to-pdf --force
  • Choose a previous stable version, for example npm install [email protected]
🌐
npm
npmjs.com › package › @pdf-viewer › react
@pdf-viewer/react - npm
August 28, 2025 - Latest version: 1.13.1, last published: 5 days ago. Start using @pdf-viewer/react in your project by running `npm i @pdf-viewer/react`. There are no other projects in the npm registry using @pdf-viewer/react.
      » npm install @pdf-viewer/react
    
Published   Dec 04, 2025
Version   1.13.1
Author   React PDF Viewer
🌐
GitHub
github.com › diegomura › react-pdf
GitHub - diegomura/react-pdf: 📄 Create PDF files using React
import React from 'react'; import { Document, Page, Text, View, StyleSheet } from '@react-pdf/renderer'; // Create styles const styles = StyleSheet.create({ page: { flexDirection: 'row', backgroundColor: '#E4E4E4', }, section: { margin: 10, ...
Starred by 16.2K users
Forked by 1.3K users
Languages   TypeScript 83.1% | JavaScript 16.8%
🌐
npm Trends
npmtrends.com › react-pdf
react-pdf | npm trends
npm trends · Display PDFs in your React app as easily as if they were images. react-pdf · Bytes is a JavaScript newsletter you'll actually enjoy reading. Delivered every Monday, for free.
🌐
Socket
socket.dev › npm › package › react-pdf-editor
react-pdf-editor - npm Package Security Analysis - Socket
December 6, 2023 - It enables users to seamlessly edit and save form fields within the PDF, ensuring compatibility with any React application while overcoming the data collection challenge associated with browser extensions.
🌐
PDF-LIB
pdf-lib.js.org
PDF-LIB · Create and modify PDF documents in any ...
$ deno run --allow-write https://pdf-lib.js.org/deno/quick_start.ts If you are using Deno, then try running the above command in your terminal to quickly create a PDF document! 🦕 · If you are using npm or yarn as your package manager:
🌐
MuPDF
mupdf.com
MuPDF: The ultimate library for managing PDF documents
MuPDF is the fast & powerful solution for managing PDF and other document formats. Extract, Convert, Merge, Split, Parse, Render, Edit, Sign, View, Annotate, Redact, Optimize PDF
🌐
PDFKit
pdfkit.org
PDFKit
Just type the following command after installing npm. ... Supports TrueType (.ttf), OpenType (.otf), WOFF, WOFF2, TrueType Collections (.ttc), and Datafork TrueType (.dfont) fonts ... See fontkit for more details on advanced glyph layout support. ... Access privileges (printing, copying, modifying, annotating, form filling, content accessibility, document assembly) Accessibility support (marked content, logical structure, Tagged PDF, PDF/UA)
🌐
GitHub
github.com › studiojms › nodejs-react-pdf-example
GitHub - studiojms/nodejs-react-pdf-example: Creating PDF with nodejs using react-pdf lib
This project is a Proof of Concept ... you need to install its dependencies: npm install · And then run · npm start · Create a PDF document based on API call (with images and styling) Go to http://localhost:4000/test?year=2012 ...
Starred by 12 users
Forked by 5 users
Languages   JavaScript