Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Uncaught TypeError: Cannot convert object to primitive value" #1895

Open
4 tasks done
kiikka opened this issue Oct 10, 2024 · 3 comments
Open
4 tasks done

"Uncaught TypeError: Cannot convert object to primitive value" #1895

kiikka opened this issue Oct 10, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@kiikka
Copy link

kiikka commented Oct 10, 2024

Before you start - checklist

  • I followed instructions in documentation written for my React-PDF version
  • I have checked if this bug is not already reported
  • I have checked if an issue is not listed in Known issues
  • If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo

Description

I'm having trouble using react-pdf to show a pdf file.

My application uses Node v20, Vite 5, Typescript and React.

Just adding the <Document> component on my page breaks the whole application and I get an error in the browsers console that goes.

Uncaught TypeError: Cannot convert object to primitive value

Steps to reproduce

  1. Create an application that uses Node v20, Vite 5 and Typescript
  2. Add <Document> component to in your React application

Expected behavior

The application won't break completely using react-pdf components.

Actual behavior

Application breaks an I get the error

Uncaught TypeError: Cannot convert object to primitive value

Additional information

This seems to only happen when running the code in Vite in development mode

Environment

  • Browser (if applicable): Chrome 129
  • React-PDF version: 9.1.1
  • React version: 18.3.1
  • Bundler name and version (if applicable): Vite 5.4.2
@kiikka kiikka added the bug Something isn't working label Oct 10, 2024
@kiikka
Copy link
Author

kiikka commented Oct 11, 2024

In the browsers console it points out to util.js row 23 typeof process === "object" &&

@kiikka
Copy link
Author

kiikka commented Oct 11, 2024

I found a workaround by adding the following code to my vite.config.ts. Though I do think maybe this should be handled in react-pdf.

  define: {
    process: JSON.stringify({}),
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants
@kiikka and others