react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

@react-pdf/pdfkit 1.3 breaks render

Open austinzentzkippdc opened this issue 7 years ago • 21 comments

Describe the bug If installing react-pdf into a clean directory, @react-pdf/pdfkit installs to 1.3, which breaks the render process with the following error: UnhandledPromiseRejectionWarning: TypeError: PDFDocument.PDFFont.open is not a function.

I manually updated my package-lock.json to install @react-pdf/pdfkit 1.2.0, which resolved the issue locally.

austinzentzkippdc avatar Oct 23 '19 18:10 austinzentzkippdc

Oh wow. Could you provide an example? I used it yesterday and worked just fine

diegomura avatar Oct 23 '19 22:10 diegomura

Nevermind. I saw it

diegomura avatar Oct 23 '19 22:10 diegomura

@diegomura I'm getting a similar error (but for @react-pdf/renderer). I'm not even loading any fonts.

TypeError: _react_pdf_pdfkit__WEBPACK_IMPORTED_MODULE_10__.PDFFont.open is not a function
    at new StandardFont (react-pdf.browser.es.js:3085)
    at getOrCreateFont (react-pdf.browser.es.js:3181)
    at react-pdf.browser.es.js:3215
    at converge.js:43
    at _map (_map.js:7)
    at converge.js:42
    at f1 (_curry1.js:16)
    at _pipe.js:3
    at _pipe.js:3
    at _pipe.js:3
    at _arity.js:11
    at apply (apply.js:26)
    at f2 (_curry2.js:28)
    at applySpec.js:53
    at applySpec.js:13
    at Array.reduce (<anonymous>)
    at mapValues (applySpec.js:12)
    at applySpec.js:52
    at f1 (_curry1.js:16)
    at _ifElse (ifElse.js:33)
    at f1 (_curry1.js:16)
    at _pipe.js:3
    at _pipe.js:3
    at _pipe.js:3
    at _pipe.js:3
    at _pipe.js:3
    at _arity.js:11
    at layoutEngine (index.js:50)
    at _curryN.js:40
    at _arity.js:16
    at Text.layoutText (react-pdf.browser.es.js:4047)
    at Text.measureText (react-pdf.browser.es.js:4060)
    at External.data (entry-common.js:264)
    at Array.eval (eval at buildJSCallerFunction (nbind.js:3855), <anonymous>:1:86)
    at Array.ASM_CONSTS (nbind.js:1366)
    at _emscripten_asm_const_iiididi (nbind.js:1382)
    at Tg (nbind.js:10185)
    at Rg (nbind.js:10162)
    at Qg (nbind.js:10143)
    at Pg (nbind.js:10114)
    at we (nbind.js:8440)
    at Yd (nbind.js:7967)
    at Td (nbind.js:6821)
    at He (nbind.js:8760)
    at Yd (nbind.js:7143)
    at Td (nbind.js:6821)
    at He (nbind.js:8760)
    at Yd (nbind.js:7143)
    at Td (nbind.js:6821)
    at _d (nbind.js:8023)

robinth91 avatar Oct 23 '19 23:10 robinth91

The error is caused due to <Text> component in my case if I remove that the issue will be resolved but I need that to display text.

vimuktj avatar Oct 24 '19 07:10 vimuktj

@vimuktj Its the Text component in my case too. If I remove that, there is no more error.

robinth91 avatar Oct 24 '19 07:10 robinth91

I've made a small experiment: created a project with "create-rect-app" then added "@react-pdf/renderer, made a small document with text fields and registered a custom font. It works with a custom font so it seems the issue is that the pdfkit can't load default fonts

greyhord avatar Oct 24 '19 08:10 greyhord

Sorry! It is indeed an issue with Text. Trying to resolve it now. For the moment you should do as @aust1nz and force not to download @react-pdf/pdfkit 1.3.0. Sorry!

diegomura avatar Oct 24 '19 14:10 diegomura

I deprecated 1.3.0 in npm. So this shouldn't happen anymore for new installs. @greyhord so is everything ok then on new installs? I think it worked for you because of 1.3.0 not being valid anymore. Everything should be as before

diegomura avatar Oct 24 '19 15:10 diegomura

Thanks for your prompt eyes on this issue. I really appreciate the library!

austinzentzkippdc avatar Oct 24 '19 15:10 austinzentzkippdc

Thank you @diegomura for the quick response! This was an issue for me when using @react-pdf/renderer too which uses this, and fixing @react-pdf/pdfkit to 1.2.0 fixed it for me.

CarlousF avatar Oct 24 '19 16:10 CarlousF

Hi @diegomura , I am still facing the issue after degrade the pdfkit. Here is the log:

bundle.js:140720 TypeError: WEBPACK_IMPORTED_MODULE_10__react_pdf_pdfkit.a.open is not a function at new StandardFont (static/js/0.chunk.js:19628) at getOrCreateFont (static/js/0.chunk.js:19724) at static/js/0.chunk.js:19758 at static/js/0.chunk.js:64474 at _map (static/js/0.chunk.js:69349) at static/js/0.chunk.js:64473 at f1 (static/js/0.chunk.js:68353) at static/js/0.chunk.js:69450 at static/js/0.chunk.js:69450 at static/js/0.chunk.js:69450 at static/js/0.chunk.js:68041 at apply (static/js/0.chunk.js:63179) at f2 (static/js/0.chunk.js:68397) at static/js/0.chunk.js:63253 at static/js/0.chunk.js:63215 at Array.reduce () at mapValues (static/js/0.chunk.js:63214) at static/js/0.chunk.js:63252 at f1 (static/js/0.chunk.js:68353) at _ifElse (static/js/0.chunk.js:66692) at f1 (static/js/0.chunk.js:68353) at static/js/0.chunk.js:69450 at static/js/0.chunk.js:69450 at static/js/0.chunk.js:69450 at static/js/0.chunk.js:69450 at static/js/0.chunk.js:69450 at static/js/0.chunk.js:68041 at layoutEngine (static/js/0.chunk.js:32493) at static/js/0.chunk.js:68511 at static/js/0.chunk.js:68045 at Text.layoutText (static/js/0.chunk.js:20590) at Text.measureText (static/js/0.chunk.js:20610) at External.data (static/js/0.chunk.js:128446) at Array.eval (eval at buildJSCallerFunction (static/js/0.chunk.js:119666), :1:86) at Array.ASM_CONSTS (static/js/0.chunk.js:118774) at _emscripten_asm_const_iiididi (static/js/0.chunk.js:118782) at Tg (static/js/0.chunk.js:121692) at Rg (static/js/0.chunk.js:121688) at Qg (static/js/0.chunk.js:121685) at Pg (static/js/0.chunk.js:121679) at we (static/js/0.chunk.js:121181) at Yd (static/js/0.chunk.js:121035) at Td (static/js/0.chunk.js:120644) at He (static/js/0.chunk.js:121282) at Yd (static/js/0.chunk.js:120766) at Td (static/js/0.chunk.js:120644) at He (static/js/0.chunk.js:121282) at Yd (static/js/0.chunk.js:120766) at Td (static/js/0.chunk.js:120644) at _d (static/js/0.chunk.js:121055)

ccyyrain avatar Oct 24 '19 20:10 ccyyrain

@diegomura The issue still exists in @react-pdf/renderer (v1.6.7) just like @ccyyrain reported above.

robinth91 avatar Oct 25 '19 00:10 robinth91

Hey guys. This issue is in @react-pdf/pdfkit, not @react-pdf/renderer. The thing is that it might be installing @react-pdf/pdfkit1.3.0. @ccyyrain please check what version ofreact-pdf/pdfkit` it's being installed, but it cannot be that you downgrade because this is definitely an issue on 1.3.0

diegomura avatar Oct 25 '19 03:10 diegomura

Hi all. @diegomura it still installs the @react-pdf/pdfkit v.1.3.0 version on clean installs despite the fact that the package is deprecated. If I edit .lock file and set it manually to 1.2.0 everything is ok.

greyhord avatar Oct 25 '19 07:10 greyhord

It probably installs 1.3.0 because the package.json for react-pdf allows it:

  "@react-pdf/pdfkit": "^1.2.0",

Allows for version ranges >= 1.2 and < 2.0, which resolves to the latest package 1.3.0 in npm.

The deprecation warning for that version does show up when yarn installing:

warning @react-pdf/renderer > @react-pdf/[email protected]: Bad build

but it still gets installed as it is the best fit for the requirement and the warning is not the most descriptive nor is it that scary for the average user, causing probable surprise when things fail..

@diegomura would recommend pushing a new version (of @react-pdf/renderer) ASAP that depends on the exact version of @react-pdf/pdfkit required (eg. 1.2.0?), as otherwise this will cause pretty much every application that uses the library to break if/when they update to 1.6.7..

matiasbuildops avatar Oct 25 '19 08:10 matiasbuildops

Hey... having the same problem, trying to use it on a pdfdownloadlink but the text issue just dont go away, tried to downgrade the pdf kit on the lock, but didnt work... someone has a work around on this? Thanks!!!

jeancrus avatar Oct 25 '19 14:10 jeancrus

Here's a simple fix if you're using Yarn. Just add the following to your package.json:

"resolutions": { "@react-pdf/pdfkit": "1.2.0" }

Then run yarn install and you should be good to go until this issue has been fixed.

xddz9 avatar Oct 25 '19 18:10 xddz9

Looks like 1.2.0 is not available (via npm at least). Uninstalled the renderer and pdfkit and reinstalled and still no joy

purpleha2e avatar Oct 26 '19 12:10 purpleha2e

1.4.0 version released! So sorry about this 😓 It turnes out I had a refactor in progress for merging react-pdf's branch with the base project, and I accidentally publish a new version on that. Won't happen again

diegomura avatar Oct 27 '19 03:10 diegomura

Thanks for the quick turnaround, Diego

purpleha2e avatar Oct 27 '19 09:10 purpleha2e