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

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

Open rajan-gupta-12 opened this issue 1 year ago • 53 comments

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.

rajan-gupta-12 avatar Aug 30 '22 06:08 rajan-gupta-12

happens for me too my version: "^2.1.1"

image

eladonline avatar Aug 30 '22 07:08 eladonline

getting same issue version - 2.1.1

image

RajasekharReddy82 avatar Aug 30 '22 12:08 RajasekharReddy82

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

eladonline avatar Aug 30 '22 13:08 eladonline

Getting a same error message.

rishipurwar1 avatar Aug 30 '22 14:08 rishipurwar1

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

OlesKravchenko avatar Aug 30 '22 15:08 OlesKravchenko

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 avatar Aug 30 '22 15:08 andyhmltn

@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 avatar Aug 30 '22 16:08 andyhmltn

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",

andyhmltn avatar Aug 30 '22 16:08 andyhmltn

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?

rajan-gupta-12 avatar Aug 30 '22 17:08 rajan-gupta-12

@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

RajasekharReddy82 avatar Aug 30 '22 18:08 RajasekharReddy82

@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" },

cayquefreitas avatar Aug 30 '22 19:08 cayquefreitas

"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

seba-cod3 avatar Aug 30 '22 20:08 seba-cod3

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

aurelien-boubennec avatar Aug 31 '22 00:08 aurelien-boubennec

@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!

rishipurwar1 avatar Aug 31 '22 05:08 rishipurwar1

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

eladonline avatar Aug 31 '22 06:08 eladonline

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 avatar Aug 31 '22 16:08 knuula

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

We would all really really appreciate it! 😃

knuula avatar Aug 31 '22 17:08 knuula

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"
      }
    },

carlobeltrame avatar Aug 31 '22 18:08 carlobeltrame

@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

andyhmltn avatar Aug 31 '22 18:08 andyhmltn

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).

carlobeltrame avatar Aug 31 '22 18:08 carlobeltrame

@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.

knuula avatar Aug 31 '22 19:08 knuula

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

carlobeltrame avatar Aug 31 '22 20:08 carlobeltrame

@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

knuula avatar Aug 31 '22 20:08 knuula

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 avatar Aug 31 '22 20:08 carlobeltrame

Here is the pull request that updated react pdf in one of my projects: https://github.com/ecamp/ecamp3/pull/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).

carlobeltrame avatar Aug 31 '22 21:08 carlobeltrame

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

marybbr avatar Aug 31 '22 21:08 marybbr

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

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 avatar Aug 31 '22 21:08 knuula

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

knuula avatar Aug 31 '22 21:08 knuula

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

[email protected] - had a default export that named all the functions image

[email protected] - just has this image

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

knuula avatar Aug 31 '22 22:08 knuula

same issue what a nightmare.

Tried the above suggestion but still did not get it to work.

image

djaffer avatar Aug 31 '22 23:08 djaffer