wojtekmaj / react-pdf

Display PDFs in your React app as easily as if they were images.
https://projects.wojtekmaj.pl/react-pdf
MIT License
9.34k stars 882 forks source link

Error registering fonts in Node through bundler (esbuild) #1823

Closed joepk90 closed 3 months ago

joepk90 commented 3 months ago

Before you start - checklist

Description

Attempting to use React PDF on the server, with custom (ttf) fonts and esbuild, throws an error:

/Projects/react-pdf-font-loading-issue/node_modules/yoga-layout/binaries/wasm-async-node.js:11
process.on("uncaughtException",function(a){throw a;});process.on("unhandledRejection",function(a){throw a;});g.inspect=function(){return"[Emscripten Module object]"};var ia=g.print||console.log.bind(console),v=g.printErr||console.warn.bind(console);Object.assign(g,ba);ba=null;var ja;g.wasmBinary&&(ja=g.wasmBinary);var noExitRuntime=g.noExitRuntime||!0;"object"!=typeof WebAssembly&&w("no native wasm support detected");var ka,la=!1;

Error: Font family not registered: roboto. Please register it calling Font.register() method.

This setup works in the browser, so perhaps this is actually a problem (or incorrect configuration) with esbuild?

However according the documentation, React PDF is meant to be compatible with esbuild, so I thought I would raise an issue here: https://react-pdf.org/compatibility#:~:text=Compatibility%20with%20esbuild

Steps to reproduce

Clone the following repo:

git clone https://github.com/joepk90/react-pdf-font-loading-issue.git

Install dependancies:

cd react-pdf-font-loading-issue
yarn

Run the following command to see reproduce the error:

make generate-pdf

Expected behavior

The expectation is to be able to generate a PDF running when running the make generate-pdf. However the generation process fails due to the error described in this Issue description

Actual behavior

The generation logic fails due to a font family failing to register.

Additional information

No response

Environment

wojtekmaj commented 3 months ago

It looks like you confused React-PDF with @react-pdf/renderer. Please file an issue in their repo instead.

joepk90 commented 3 months ago

It looks like you confused React-PDF with @react-pdf/renderer. Please file an issue in their repo instead.

Ah, apologies - You are correct.

I will open an issue with @react-pdf/renderer 👍