PDF Generation Fails with @react-pdf/renderer on Railway (React Error #31)
devkidjef
FREEOP

9 months ago

Hi all,

I am unable to generate PDFs using @react-pdf/renderer in our Next.js 15 app deployed on Railway.

  • PDF generation works perfectly in local development.

  • On Railway, even a minimal PDF template (just a single <Text>) fails.

  • This was also the reason we left Vercel, where PDF generation never worked.

Error Messages:
[PDF Generation] Error generating PDF buffer: [Error: Minified React error #31; visit https://reactjs.org/docs/error-decoder.html?invariant=31&args[]=object%20with%20keys%20%7B%24%24typeof%2C%20type%2C%20key%2C%20ref%2C%20props%7D&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.]

This is the classic “Objects are not valid as a React child” error, but it happens even with the most basic PDF template.

Relevant Logs (Deploy/Runtime):
[API generate-pdf] Received request for PDF generation.

[API generate-pdf] Generating PDF directly in API route with full ReportTemplate...

[PDF Generation] Error generating PDF buffer: [Error: Minified React error #31; ...]

[API generate-pdf] Error in GET handler for project ...: [Error: Minified React error #31; ...]

I also see:
[chartGenerator] Canvas/chart generation not available in this environment: [Error: libuuid.so.1: cannot open shared object file: No such file or directory]

But chart generation falls back to QuickChart, so this is not the root cause.

Questions:

  • Is there a known incompatibility with @react-pdf/renderer or server-side PDF generation on Railway?

  • Could this be related to a limitation of the free tier (e.g., missing native modules, memory, or WASM support)?

  • Are there any workarounds or configuration changes I can try?

    Many thanks for any clues or information!

    Cheers,
    jef

$10 Bounty

5 Replies

guilhermealves18
FREE

9 months ago

First of all, sorry for my bad English... I'm still learning :)

Secondly, Hello!

I had problems with buffers in Railway, the support told me that Railway doesn't modify the request body, but for some reason it was being modified...

You first need to check if the body of your Buffer is not being modified when you generate your PDF.

Check if you are using proxies, if so, try disabling them to test.


devkidjef
FREEOP

9 months ago

Hi, thanks a lot for your reply and your English is totally fine, no worries! blush emoji

That’s a helpful suggestion. In my case though, the PDF generation fails before any response is sent or any buffer is returned. I’m using @react-pdf/renderer, and even with a minimal “Hello World” PDF template, the error occurs during the renderToBuffer() call on Railway.

The specific error I’m getting is:
Minified React error #31: Objects are not valid as a React child...

This happens consistently on Railway, even with the most basic template. It works fine in local dev.

So I suspect the issue is more about runtime incompatibility – maybe a Node.js version issue, or missing native/WASM support for the PDF renderer in Railway’s environment.

Still, I really appreciate your input!

Thanks again,
Jef


ju-li
PRO

9 months ago

I don't think the issue is with Railway. I vibe coded a quick and dirty Nextjs 15 app that randomly generates a PDF with lorem ipsum and an UUID: https://github.com/ju-li/test-pdf-gen-react

Deployed it and it works: https://test-pdf-gen-react-production.up.railway.app/

I am on the pro tier tho. So I can't confirm if the issue is with free tier limits.


ju-li

I don't think the issue is with Railway. I vibe coded a quick and dirty Nextjs 15 app that randomly generates a PDF with lorem ipsum and an UUID: https://github.com/ju-li/test-pdf-gen-reactDeployed it and it works: https://test-pdf-gen-react-production.up.railway.app/I am on the pro tier tho. So I can't confirm if the issue is with free tier limits.

devkidjef
FREEOP

9 months ago

Hey ju-li, many thanks for generating that test. I will surely look into it and report back. Awesome!

Thanks!


devkidjef

Hey ju-li, many thanks for generating that test. I will surely look into it and report back. Awesome!Thanks!

ju-li
PRO

9 months ago

Np! To test if it's a free tier limitation, try deploying my test repo in your workspace


Loading...