OnedocLabs / react-print-pdf

Build and generate PDF using React 📄 UI kit for PDFs and print documents. Simple, reusable components and templates to create great invoices, docs, brochures. Use your favorite front-end framework React to build your next PDF.
https://docs.fileforge.com/react-print/welcome/getting-started
Apache License 2.0
2.31k stars 87 forks source link

OS platforms is required and other Node.js refs #5

Closed the-homeless-god closed 8 months ago

the-homeless-god commented 9 months ago
image image

Looks like os.platform is not available by default

❯ node --version
v20.6.1

❯ npm --version
np9.8.1
the-homeless-god commented 9 months ago

Looks like a lot of Node.js references.

the-homeless-god commented 9 months ago

Same situation for react-scripts just at the project built from scratch

image
the-homeless-god commented 9 months ago

Same for Next.js

It looks like the reason is tailwind

image image image
Titou325 commented 9 months ago

Hey @the-homeless-god, Tailwind support is server-side only so you may be encountering these issues as Tailwind parses a list of files to detect classes. However under our implementation we should be able to get going without scouting all files. I'll have a look

eliasamaral commented 9 months ago

I face the same issue, and my web application doesn't use Tailwind. The error already appears upon import.

Titou325 commented 9 months ago

Hi @eliasamaral @the-homeless-god I am not able to reproduce this on my end. Would you have a sample repo or more repro steps on how you used the library so I can give a better look? Thanks!

the-homeless-god commented 9 months ago

Hi @eliasamaral @the-homeless-god I am not able to reproduce this on my end. Would you have a sample repo or more repro steps on how you used the library so I can give a better look? Thanks!

I've just created app via create-react-app, or next.js, or vite from scratch I will create a sample repo for you tomorrow, but the most important thing is:

npx create-react-app npm i react-print-pdf

and try to configure by guide and start an application. It will fail.

Titou325 commented 9 months ago

I would expect vite and create-react-app to fail as they are frontend only and we have an issue with tsup to bundle file system dependencies without a file system. Next should work though.

I'd be glad to take a look at the Next.js example. We use Next as our own backend and it seems to work for us as long as the docs are generated in API or pages rather than client components.

Thank you very much for your help!

eliasamaral commented 8 months ago

Just creating a clean project in Vite, without any added dependencies, is already enough to encounter the error. Take a look at this repo: https://github.com/eliasamaral/Onedoc_issues_-5/tree/main/vite-project

Titou325 commented 8 months ago

Hey guys!

We dug deeper into this and because of a complex behavior of Tailwind when used with PostCSS, we can't port the Tailwind handling to the client as of now.

Given that the rest of react-print-pdf does not rely on Tailwind and can be ported to the client, we have created a sub-import at @onedoc/react-print-pdf/client that allows import of all client-compatible components without overlap. In the near future we will split each component to a separate bundle to prevent this from happening.

The docs have been updated to show the support for each component (i.e. https://react.onedoclabs.com/components/tailwind)

I will close this issue and create a new one for Tailwind specifically.

Thanks!