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

Attempted import error: 'create' is not exported from 'fontkit' (imported as 'fontkit'). #1991

Closed
rajan-gupta-12 opened this issue Aug 30, 2022 · 64 comments · Fixed by #2023
Closed

Comments

@rajan-gupta-12
Copy link

After the upgradation, we are getting the below error in local and while deploying the code. Please help here.

image

Current version in our machine : @react-pdf/renderer": "^2.0.16"

@diegomura Please help check ASAP.

@eladonline
Copy link

eladonline commented Aug 30, 2022

happens for me too
my version: "^2.1.1"

image

@RajasekharReddy82
Copy link

getting same issue
version - 2.1.1

image

@eladonline
Copy link

I think the problem might be a typo: the latest package of fontkit is 2.0.2
and in the node-modules is see it installs 2.1.2

@rishipurwar1
Copy link

Getting a same error message.

@OlesKravchenko
Copy link

I have same problem with version 3.0.0, old versions have same error

@andyhmltn
Copy link

andyhmltn commented Aug 30, 2022

Experiencing the same thing. Seems like a new version of react-pdf/font has been released that contains a breaking change. As the dependencies are listed using ^ npm / yarn will automatically upgrade the next minor version. So when removing yarn.lock and reinstalling, a new version with the issue is installed. Here's my yarn.lock diff:

Screenshot 2022-08-30 at 16 44 38

Notice the resolved url in the green now shows 2.3.0 not 2.2.0

@andyhmltn
Copy link

@eladonline @RajasekharReddy82 @rishipurwar1 If you're using renderer version 2.1.1 this can be solved relatively easily.

Add:

"@react-pdf/font": "2.2.0",

To your package.json dependencies.

Then add:

"resolutions": {
    "@react-pdf/font": "2.2.0"
  },

If you already have a resolutions object you'll just need to add this version to it. Notice there is no ^ in the version number.

Then remove yarn.lock or package-lock.json and re-run yarn/npm install

@andyhmltn
Copy link

Also the above only worked for me when I made sure react-pdf/renderer was pinned to 2.1.0. So: "@react-pdf/renderer": "2.1.0",

@rajan-gupta-12
Copy link
Author

rajan-gupta-12 commented Aug 30, 2022

Also the above only worked for me when I made sure react-pdf/renderer was pinned to 2.1.0. So: "@react-pdf/renderer": "2.1.0",

If i use mentioned version , will it work?

@RajasekharReddy82
Copy link

@eladonline @RajasekharReddy82 @rishipurwar1 If you're using renderer version 2.1.1 this can be solved relatively easily.

Add:

"@react-pdf/font": "2.2.0",

To your package.json dependencies.

Then add:

"resolutions": {
    "@react-pdf/font": "2.2.0"
  },

If you already have a resolutions object you'll just need to add this version to it. Notice there is no ^ in the version number.

Then remove yarn.lock or package-lock.json and re-run yarn/npm install

@andyhmltn Thank you its works for me

@cayquefreitas
Copy link

cayquefreitas commented Aug 30, 2022

@eladonline @RajasekharReddy82 @rishipurwar1 If you're using renderer version 2.1.1 this can be solved relatively easily.

Add:

"@react-pdf/font": "2.2.0",

To your package.json dependencies.

Then add:

"resolutions": {
    "@react-pdf/font": "2.2.0"
  },

If you already have a resolutions object you'll just need to add this version to it. Notice there is no ^ in the version number.

Then remove yarn.lock or package-lock.json and re-run yarn/npm install

@andyhmltn Thank you for pointing out the problem, worked for me as well.
Just had to add these "overrides" for my build to work.

"overrides": { "@react-pdf/font": "2.2.0" },

@seba-cod3
Copy link

"resolutions": {
"@react-pdf/font": "2.2.0"
},

@eladonline @RajasekharReddy82 @rishipurwar1 If you're using renderer version 2.1.1 this can be solved relatively easily.

Add:

"@react-pdf/font": "2.2.0",

To your package.json dependencies.

Then add:

"resolutions": {
    "@react-pdf/font": "2.2.0"
  },

If you already have a resolutions object you'll just need to add this version to it. Notice there is no ^ in the version number.

Then remove yarn.lock or package-lock.json and re-run yarn/npm install

Thank you friend, u have made my day

@aurelien-boubennec
Copy link

aurelien-boubennec commented Aug 31, 2022

Same issue but fails with my build script in CodeBuild only.

@rishipurwar1
Copy link

@eladonline @RajasekharReddy82 @rishipurwar1 If you're using renderer version 2.1.1 this can be solved relatively easily.

Add:

"@react-pdf/font": "2.2.0",

To your package.json dependencies.

Then add:

"resolutions": {
    "@react-pdf/font": "2.2.0"
  },

If you already have a resolutions object you'll just need to add this version to it. Notice there is no ^ in the version number.

Then remove yarn.lock or package-lock.json and re-run yarn/npm install

Worked for me, Thanks!

@eladonline
Copy link

Also the above only worked for me when I made sure react-pdf/renderer was pinned to 2.1.0. So: "@react-pdf/renderer": "2.1.0",

your a life saver

@knuula
Copy link
Sponsor

knuula commented Aug 31, 2022

Any updates on this @diegomura - I can get it working locally but not when it compiles on our hosting service (use AWS Amplify for hosting)

@knuula
Copy link
Sponsor

knuula commented Aug 31, 2022

Any updates on this: @carlobeltrame @jeetiss @diegomura @adamduncan @PhilippMeissner

We would all really really appreciate it! 😃

@carlobeltrame
Copy link
Contributor

Can you try with the most recent version npm install @react-pdf/renderer@^3.0.0? There were some changes regarding fontkit in that release and I don't think there will be a lot of support for versions like 2.0.16 or 2.1.1

I have same problem with version 3.0.0, old versions have same error

@OlesKravchenko Are you working in Node or in the browser? Please provide a reproduction.
I am using 3.0.0 in the browser, works great, both locally and in a built application. My package-lock.json contains:

"node_modules/@react-pdf/font": {
      "version": "2.3.0",
      "resolved": "https://registry.npmjs.org/@react-pdf/font/-/font-2.3.0.tgz",
      "integrity": "sha512-+O1TR0gYnlJe3BUMVcT+5skAq7CwxgbiCPQneXmZbITeQMdqAVxPhVskIC7t3f7hg0YgZKG5e2L+11TD7uHbKQ==",
      "dependencies": {
        "@babel/runtime": "^7.16.4",
        "@react-pdf/types": "^2.0.9",
        "base64-to-uint8array": "^1.0.0",
        "cross-fetch": "^3.1.5",
        "fontkit": "^2.0.2",
        "is-url": "^1.2.4"
      }
    },
    "node_modules/@react-pdf/renderer": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/@react-pdf/renderer/-/renderer-3.0.0.tgz",
      "integrity": "sha512-1eTqNdl2+ZIC85L7NmPkUmyurZDLK1nernqvRlHVMMauB4rA3UkB0Y2Z8bHMUvB+t2s4rNlMJ+RZdrR5H/JGpw==",
      "dependencies": {
        "@babel/runtime": "^7.16.4",
        "@react-pdf/font": "^2.3.0",
        "@react-pdf/layout": "^3.2.0",
        "@react-pdf/pdfkit": "^3.0.0",
        "@react-pdf/primitives": "^3.0.0",
        "@react-pdf/render": "^3.2.1",
        "@react-pdf/types": "^2.1.0",
        "queue": "^6.0.1",
        "react-reconciler": "^0.23.0",
        "scheduler": "^0.17.0"
      },
      "peerDependencies": {
        "react": "^16.8.6 || ^17.0.0"
      }
    },

@andyhmltn
Copy link

andyhmltn commented Aug 31, 2022

@carlobeltrame Is it not possible to fix without upgrading to 3.0.0? This should really be a major version upgrade for react-pdf/font if not if it will remove backwards compatibility. This will prevent yarn / npm automatically updating the package when using ^ in package.json. Our deploys broke randomly when this version was pushed which shouldn't be the case with a minor version update

@carlobeltrame
Copy link
Contributor

The only reason why it's a major version upgrade for @react-pdf/renderer is that support for Node 12 was dropped. It's really not a major upgrade in the classical sense. For the same reason, there is also no upgrade guide for upgrading to 3.0.0. There simply is nothing you would have to change in your code (unless you were using vite-plugin-shim-react-pdf before, in which case you would have to remove that when upgrading to 3.0.0).

@knuula
Copy link
Sponsor

knuula commented Aug 31, 2022

@carlobeltrame - tried upgrading to 3.0.0 and it fails to run in the browser with the same issue as everyone above.

I can get it running in the browser with something like this below:
react-pdf-dependencies
react-pdf-resolutions

But, that does not compile when we deploy it.

@carlobeltrame
Copy link
Contributor

Well, that's still not the most recent versions of the packages, see above my versions in package-lock. Not sure why it lets you keep the old versions, there might be something misconfigured in react-pdf. But if you force the same versions as me, do you keep having the error? Please note that @react-pdf/fontkit is discontinued, react-pdf switched back to using the original foliojs/fontkit package, so that package should no longer be installed when using renderer v3.0.0

@knuula
Copy link
Sponsor

knuula commented Aug 31, 2022

@carlobeltrame - I added those packages without the ^. And added those resolutions as well. It was the only way I could get it running in the browser.

any time I've installed @react-pdf/renderer@^3.0.0 - nothing will run. not even in the browser.

I am seeing that when we install @react-pdf/renderer - it is adding in all the other @react-pdf libraries (not just /renderer).

react-pdf-libs

The actual compiling error is coming from @react-pdf/pdfkit/lib/pdfkit.browser.es.js

image

@carlobeltrame
Copy link
Contributor

Can you provide a minimal reproduction example in a git repositorysomewhere so I can check?
No idea how you ugrade your packages, but if you still have @react-pdf/fontkit something is wrong. All the other @react-pdf packages are fine to still be there

@carlobeltrame
Copy link
Contributor

Here is the pull request that updated react pdf in one of my projects: ecamp/ecamp3#2949
As you can see in the diff of package-lock.json, @react-pdf/fontkit was removed, and on line 10085, fontkit was added. Maybe that diff helps you.
If you either ran something like npm install @react-pdf/renderer@latest or manually changed package.json and the ran npm install, there should be no @react-pdf/fontkit left in your package-lock.json (unless you explicitly installed that package in package.json, which you should only do if you know what you are doing).

@marybbr
Copy link

marybbr commented Aug 31, 2022

I still have same error even after doing what @andyhmltn suggested.

@knuula
Copy link
Sponsor

knuula commented Aug 31, 2022

I can't really share it right now but I just went ahead and updated pretty much everything - include node and npm

  • removed all node_modules + package-lock.json
  • add react-pdf/renderer@3.0.0

here node_modules/@react-pdf
image

it does not contain @react-pdf/fontkit - so that's good I guess

here is where errors are coming from:
image
image

it seems like it is trying to use "fontkit", not @react-pdf/fontkit

very unsure on what is going on so I am just throwing this out there... it seems like the issue is coming from fontkit specifically (NOT @react-pdf/fontkit)

@knuula
Copy link
Sponsor

knuula commented Aug 31, 2022

@marybbr - don't listen to me! I'm still not sure what is going on. Looking for answers

@knuula
Copy link
Sponsor

knuula commented Aug 31, 2022

digging into this deeper... does @carlobeltrame @Sebastian-Cor @andyhmltn or anyone else know how to get around this??

fontkit@1.9.0 - had a default export that named all the functions
image

fontkit@2.0.2 - just has this
image

pretty sure this is where some of the issues are coming from. any ideas on getting around this?

@djaffer
Copy link

djaffer commented Sep 1, 2022

The only reason why it's a major version upgrade for @react-pdf/renderer is that support for Node 12 was dropped. It's really not a major upgrade in the classical sense. For the same reason, there is also no upgrade guide for upgrading to 3.0.0. There simply is nothing you would have to change in your code (unless you were using vite-plugin-shim-react-pdf before, in which case you would have to remove that when upgrading to 3.0.0).

Right okay, fair enough. Still dropping support for a node version does seem like a breaking change for me. We aren't locked into node versions here but I have worked at companies in the past where they are locked on specific node versions due to legacy packages. Upgrading to 3.0.0 would be off the table in that instance and so no way to fix without resorting to manually updating the resolutions.

This was working fine previously before the new minor version patch so a better solution would just be to properly pin the versions for the packages react-pdf/renderer requires. This completely avoids this situation from happening where pipelines break with no dev intervention because of a minor patch.

Agree with @Sebastian-Cor: Fantastic package that's really helping us. But the versioning could be improved to prevent this from happening.

@marybbr Have you removed yarn.lock before re-installing? If so, what version of react-pdf/font is listed in your lock file?

It is not just upgrading 1 package there are multiple dependencies associated with it like react, react history that might not be compatible with the codebase. This blanket approach can cause drastic breakage. In this case, the automatic uptick is the issue. Pushing a breaking new major version is fine as it gives the option to choose whether to move to the next or not. I think the author just needs to make the new fontkit only applicable to version v3.0 rather than anything for v2.

@marybbr
Copy link

marybbr commented Sep 1, 2022

@carlobeltrame the last version has the problem which this issue based on. I should have changed the version to prevent my code crashing and this was the only solution here which @andyhmltn suggested but still doesn't work for me.

@carlobeltrame
Copy link
Contributor

Ah I see, you were trying to downgrade. You would probably have to pin (using resolutions) the versions of all the @react-pdf packages to do make that work somewhat reliably. But I definitely wouldn't recommend that.

Anyways, the latest version does not have any problem if you upgrade correctly, using one of the two standard ways I described above. I am using it myself. If you do have a problem with 3.0.0, please someone provide a reproduction repository so we can fix the problem. Otherwise you will all be stuck with the old version forever...

@djaffer
Copy link

djaffer commented Sep 1, 2022

Ok so I have released a new package with the fix of reverting the latest commit to the previous version 2.3.0 and setting the sub dependencies to the exact version without uptick. Also, fixed the version for babel was incorrect that was not found. I have published a new package with these changes while maintaining credits to the author and contributors. It is working for me! Hope it unblocks you guys until this repo gets fix.

For now, try out

npm i react-pdf-renderer-v2 

yarn install react-pdf-renderer-v2

https://www.npmjs.com/package/react-pdf-renderer-v2

master...djaffer:react-pdf:master

@seba-cod3
Copy link

@marybbr have you done a clean install? rm -rf node_modules && rm -rf package-lock.json && npm i ?

@marybbr
Copy link

marybbr commented Sep 1, 2022

@Sebastian-Cor yes I did; anything doesn't work # until I cleaned npm catch and although the font package version is wrong, but at least it works now 😬

@carlobeltrame
Copy link
Contributor

carlobeltrame commented Sep 2, 2022

Alright guys, I am unsubscribing from notifications on this issue now, since it looks like you don't want the help of me or the maintainers of this package anymore. May I suggest we close this issue and you continue the discussion on @djaffer's repository, since it is not relevant anymore to @diegomura's react-pdf? @djaffer you might have to enable issues on your repository.

@djaffer
Copy link

djaffer commented Sep 2, 2022

There is no need for the issue to continue on mine. I have suggested the fix that is working for me to unblock myself and maybe other users can use it too. The issue still belongs to this repo. I am not going to maintain that repo and just have it as a workaround. Once this repo adopts the fix I can remove the package.

@Avni-Inteliyo
Copy link

@eladonline @RajasekharReddy82 @rishipurwar1 If you're using renderer version 2.1.1 this can be solved relatively easily.

Add:

"@react-pdf/font": "2.2.0",

To your package.json dependencies.

Then add:

"resolutions": {
    "@react-pdf/font": "2.2.0"
  },

If you already have a resolutions object you'll just need to add this version to it. Notice there is no ^ in the version number.

Then remove yarn.lock or package-lock.json and re-run yarn/npm install

I tried the same but it's not working in my case. My react version is 17.0.2.
What's yours?

@Swastikyadav
Copy link

@eladonline @RajasekharReddy82 @rishipurwar1 If you're using renderer version 2.1.1 this can be solved relatively easily.

Add:

"@react-pdf/font": "2.2.0",

To your package.json dependencies.

Then add:

"resolutions": {
    "@react-pdf/font": "2.2.0"
  },

If you already have a resolutions object you'll just need to add this version to it. Notice there is no ^ in the version number.

Then remove yarn.lock or package-lock.json and re-run yarn/npm install

Just removing the ^ symbol from "@react-pdf/renderer" and adding "@react-pdf/font": "2.2.0" in package.json worked for me. No need to change renderer version or add resolution object.

"@react-pdf/renderer": "2.1.1",
 "@react-pdf/font": "2.2.0",

@andrew-tacklit
Copy link

I'm encountering this issue too...

@marsmallos
Copy link

Me too! please fix it.

  "dependencies": {
    "@react-pdf/font": "^2.2.1",
    "@react-pdf/renderer": "^3.0.0",

@vipindigiqt
Copy link

I'm looking for an alternative, This package is awesome, but I don't want to deal with this type of issues. No offence to anyone though, I appreciate the Open Source work, but I'm having a hard time dealing with this package.

@yurisz
Copy link

yurisz commented Sep 12, 2022

@eladonline @RajasekharReddy82 @rishipurwar1 If you're using renderer version 2.1.1 this can be solved relatively easily.
Add:

"@react-pdf/font": "2.2.0",

To your package.json dependencies.
Then add:

"resolutions": {
    "@react-pdf/font": "2.2.0"
  },

If you already have a resolutions object you'll just need to add this version to it. Notice there is no ^ in the version number.
Then remove yarn.lock or package-lock.json and re-run yarn/npm install

Just removing the ^ symbol from "@react-pdf/renderer" and adding "@react-pdf/font": "2.2.0" in package.json worked for me. No need to change renderer version or add resolution object.

"@react-pdf/renderer": "2.1.1",
 "@react-pdf/font": "2.2.0",

Work here. Thanks.

iSudo added a commit to maanteeamet/digitransit-ui that referenced this issue Sep 12, 2022
diegomura/react-pdf#1991
react-pdf/renderer broke because react-pdf/font package was updated solution is to set the version of font to 2.0.2
@Manos-Kar
Copy link

@eladonline @RajasekharReddy82 @rishipurwar1 If you're using renderer version 2.1.1 this can be solved relatively easily.

Add:

"@react-pdf/font": "2.2.0",

To your package.json dependencies.

Then add:

"resolutions": {
    "@react-pdf/font": "2.2.0"
  },

If you already have a resolutions object you'll just need to add this version to it. Notice there is no ^ in the version number.

Then remove yarn.lock or package-lock.json and re-run yarn/npm install

This also worked for me. Please pay attention to remove the ^ symbol from "@react-pdf/renderer"!!

We spent a lot of time wondering why everyone says it's working and it didn't work for us...

@RrNn
Copy link

RrNn commented Sep 13, 2022

Using React version ^16.14.0 with @react-pdf/renderer": "^2.2.0 and i upgraded like;

  • Updated @react-pdf/renderer from ^2.2.0 to 3.0.0
  • Added an overrides key to my package.json that looks like;
"overrides": {
    "@react-pdf/font": "2.2.1",
    "@react-pdf/pdfkit": "2.1.0"
  }

Note that I am using npm not yarn
So, finally i have a package.json that looks like;

// other stuff in the package.json file
"dependencies": {
// other dependencies in the package.json file
   "@react-pdf/renderer": "3.0.0"
}
"overrides": {
    "@react-pdf/font": "2.2.1",
    "@react-pdf/pdfkit": "2.1.0"
}
// other stuff in the package.json file

And everything worked fine after that

@RossLYoung
Copy link

For anyone using create-react-app, I got @react-pdf/renderer": "^3.0.0" working by updating react-scripts to 5.0.1 and "npm install --save buffer"

No other react-pdf packages in my dependencies and nothing in my overrides or resolutions object.

@vipindigiqt
Copy link

For anyone using create-react-app, I got @react-pdf/renderer": "^3.0.0" working by updating react-scripts to 5.0.1 and "npm install --save buffer"

No other react-pdf packages in my dependencies and nothing in my overrides or resolutions object.

And do you have any reasoning for why do we need buffer ?

@carlobeltrame
Copy link
Contributor

carlobeltrame commented Sep 29, 2022

Hey guys, I found out over at #2028 that this error happens due to an issue in webpack 4. Upgrading to webpack 5 solved the problem there.

Actually, it looks like @RossLYoung beat me to it with finding that, since react-scripts is likely the package which determines the webpack version in their project. But the buffer dependency should not be necessary.

If you cannot update to webpack 5, you either have to eject and adjust your config as described here (or use craco or something similar to do that), or stay on @react-pdf/renderer < 3.0.0 until facebook/create-react-app#12605 or facebook/create-react-app#12021 is merged and released, and then update create-react-app.

@RossLYoung
Copy link

@vipindigiqt, once I had it nearly working with webpack 5 by updating react-scripts, I only had this buffer error #2016.
There's another mention of a buffer problem above #1991 (comment)

@carlobeltrame, I had the same buffer error that you commented on in #2016 (comment)
The buffer error was coming from node_modules/base64-to-uint8array/index.js
The only thing that requires base64-to-uint8array in my package-lock.json is @react-pdf/font:"2.3.0"

I hope that is of some use.

@carlobeltrame
Copy link
Contributor

The buffer error was coming from node_modules/base64-to-uint8array/index.js

Ah, true, there is still some buffer problem. I have PR #2023 open to fix that. Once that is merged and released, buffer shouldn't be necessary anymore.

@genie4viz
Copy link

I am still getting this error with @react-pdf/renderer 3.0.0.
'create' is not exported from 'fontkit' (imported as 'fontkit')
Is there any perfect solution?
I am using react 17.0.2.

@marsmallos
Copy link

I am still getting this error with @react-pdf/renderer 3.0.0. 'create' is not exported from 'fontkit' (imported as 'fontkit') Is there any perfect solution? I am using react 17.0.2.

I solved this by downgrading a bunch of packages and using the renderer v.2.0.19. Not sure if my solution is perfect but at least it worked for me. See my answer here: #2015 (comment)

@genie4viz
Copy link

genie4viz commented Oct 14, 2022

@marsmallos
Thank you very much! It really works great!

@zulalnb
Copy link

zulalnb commented Nov 11, 2022

@eladonline @RajasekharReddy82 @rishipurwar1 If you're using renderer version 2.1.1 this can be solved relatively easily.

Add:

"@react-pdf/font": "2.2.0",

To your package.json dependencies.

Then add:

"resolutions": {
    "@react-pdf/font": "2.2.0"
  },

If you already have a resolutions object you'll just need to add this version to it. Notice there is no ^ in the version number.

Then remove yarn.lock or package-lock.json and re-run yarn/npm install

I tried this to upgrade from 2.3.0 but it didn't work for me. Is there any solution for 2.3.0?

@surajdhungana46
Copy link

Okay, I fixed this all the way on my end. Feel free to go for this: @djaffer @marybbr @rajan-gupta-12

root issue (I think) was react-scripts for me. Here's what all I did.

  • updated node to the latest version
  • updated npm to the latest version
  • updated react-scripts to 5.0.1
  • @react-pdf/renderer@3.0.0
  • got some "reference error: process not defined" errors when I tried to run locally
  • did everything that this person said https://bobbyhadz.com/blog/react-referenceerror-process-not-defined
  • had to add some stuff like this to index.js
    image

everything works correctly locally now with @react-pdf/renderer

I was also able to successfully build and deploy the frontend, so it compiled correctly.

I think the issue was something to do with fontkit@2.0.2 not using this format anymore:

image

Okay, I fixed this all the way on my end. Feel free to go for this: @djaffer @marybbr @rajan-gupta-12

root issue (I think) was react-scripts for me. Here's what all I did.

  • updated node to the latest version
  • updated npm to the latest version
  • updated react-scripts to 5.0.1
  • @react-pdf/renderer@3.0.0
  • got some "reference error: process not defined" errors when I tried to run locally
  • did everything that this person said https://bobbyhadz.com/blog/react-referenceerror-process-not-defined
  • had to add some stuff like this to index.js
    image

everything works correctly locally now with @react-pdf/renderer

I was also able to successfully build and deploy the frontend, so it compiled correctly.

I think the issue was something to do with fontkit@2.0.2 not using this format anymore:

image

Have you fix above issue ? still got same problem?

@robb216
Copy link

robb216 commented Mar 13, 2023

@vipindigiqt, once I had it nearly working with webpack 5 by updating react-scripts, I only had this buffer error #2016. There's another mention of a buffer problem above #1991 (comment)

@carlobeltrame, I had the same buffer error that you commented on in #2016 (comment) The buffer error was coming from node_modules/base64-to-uint8array/index.js The only thing that requires base64-to-uint8array in my package-lock.json is @react-pdf/font:"2.3.0"

I hope that is of some use.

Updating webpack (react-scripts) to 5 opens another can of worms, webpack 5 no longer automatically polyfills some node.js modules. All webpack@5 compatible libraries should provide these polyfills.

However, some older webpack@4 compatible libraries may not include these polyfills by default. To make these work with webpack@5, you need to manually add these modules (yarn add buffer --dev) and then add them to your webpack config.

If you're using create-react-app (react-scripts), you cannot under normal circumstances modify your webpack config, but I had some success using react-app-rewired to modify my webpack config, and node-polyfill-webpack-plugin to automatically add the polyfills I needed.

Updating to webpack 5 and using @react-pdf/renderer@3.1.7 did solve the issue for me! Hope this helps someone.

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.