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

I can't use renderToBuffer, renderToStream, etc ... in server side with NextJS 13+ with App router #2460

Closed
mrkjofficial opened this issue Dec 10, 2023 · 8 comments

Comments

@mrkjofficial
Copy link

mrkjofficial commented Dec 10, 2023

Describe the bug
In Next.js 13+ using App router , I'm unable to render PDF in Stream or Buffer in Next API routes

Error Message
'ba.Component is not a constructor'

To Reproduce
Steps to reproduce the behavior including code snippet (if applies):

  1. Create a new Next.js porject select App Router during setup.
  2. Add @react-pdf/renderer in the project.
  3. Create a dummy PDF.
  4. Try to render the PDF in the server side.

Expected behavior
App should run, react-pdf should render pdfs.

Desktop (please complete the following information):

  • OS: Windows
  • Browser Chrome
  • React-pdf version v3.1.14
@jameschetwood
Copy link

Try using the pages router instead. This worked for me.

@mrkjofficial
Copy link
Author

Try using the pages router instead. This worked for me.

No solutions for app router yet? My whole application is based on the App router.

@Dru1DD
Copy link

Dru1DD commented Dec 26, 2023

Unfortunetly, you can you @joshuajaco/react-pdf-renderer-bundled, but if you using packages like @david.kucsai/react-pdf-table you would have a problem, that it doesn't work with App Router. On Client component yeah, but in server component when you tried to use renderToBuffer - unfortunetly - not(

@bordeo
Copy link

bordeo commented Dec 29, 2023

I think you should resolve using transpilePackages as I mention here

@Dru1DD
Copy link

Dru1DD commented Dec 29, 2023

You can create pages/api - route even in App Router and it works

@wojtekmaj
Copy link
Contributor

Duplicate of #2350

wojtekmaj added a commit to wojtekmaj/diegomura-react-pdf that referenced this issue Jan 18, 2024
Fixes diegomura#2350
Fixes diegomura#2460

This proposal bundles React with @react-pdf/renderer.

The reason for that is Next.js replacing current React version with `18.3.0-canary-8c8ee9ee6-20231026`, which is not compatible with any stable version of react-reconciler available at the moment.

I realize that this is a huge change and I'm actually not convinced it's the right way to go, but if anyone would e.g. like to make a custom build on their own, this PR makes it possible to use @react-pdf/renderer in Next.js route handlers seamlessly.
wojtekmaj added a commit to wojtekmaj/diegomura-react-pdf that referenced this issue Jan 18, 2024
Fixes diegomura#2350
Fixes diegomura#2460

This proposal bundles React with @react-pdf/renderer.

The reason for that is Next.js replacing current React version with `18.3.0-canary-8c8ee9ee6-20231026`, which is not compatible with any stable version of react-reconciler available at the moment.

I realize that this is a huge change and I'm actually not convinced it's the right way to go, but if anyone would e.g. like to make a custom build on their own, this PR makes it possible to use @react-pdf/renderer in Next.js route handlers seamlessly.
@airtonix
Copy link

You can create pages/api - route even in App Router and it works

That's fine if you want to create a server side endpoint for use at runtime, but remember that just because someone is using the apps/* directory, doesn't mean that they are running nextjs server side at runtime.

https://nextjs.org/docs/pages/building-your-application/deploying/static-exports

@diegomura
Copy link
Owner

Closing it as duplicated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants