react-pdf
react-pdf copied to clipboard
Attempted import error: 'create' is not exported from 'fontkit' (imported as 'fontkit').
After the upgradation, we are getting the below error in local and while deploying the code. Please help here.
Current version in our machine : @react-pdf/renderer": "^2.0.16"
@diegomura Please help check ASAP.
happens for me too my version: "^2.1.1"
getting same issue version - 2.1.1
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
Getting a same error message.
I have same problem with version 3.0.0, old versions have same error
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:
Notice the resolved
url in the green now shows 2.3.0 not 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
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",
Also the above only worked for me when I made sure
react-pdf/renderer
was pinned to2.1.0
. So:"@react-pdf/renderer": "2.1.0",
If i use mentioned version , will it work?
@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
orpackage-lock.json
and re-runyarn
/npm install
@andyhmltn Thank you its works for me
@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
orpackage-lock.json
and re-runyarn
/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" },
"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
orpackage-lock.json
and re-runyarn
/npm install
Thank you friend, u have made my day
Same issue but fails with my build script in CodeBuild only.
@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
orpackage-lock.json
and re-runyarn
/npm install
Worked for me, Thanks!
Also the above only worked for me when I made sure
react-pdf/renderer
was pinned to2.1.0
. So:"@react-pdf/renderer": "2.1.0",
your a life saver
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)
Any updates on this: @carlobeltrame @jeetiss @diegomura @adamduncan @PhilippMeissner
We would all really really appreciate it! 😃
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 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
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 - 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:
But, that does not compile when we deploy it.
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 - 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).
The actual compiling error is coming from @react-pdf/pdfkit/lib/pdfkit.browser.es.js
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
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).
I still have same error even after doing what @andyhmltn suggested.
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/[email protected]
here node_modules/@react-pdf
it does not contain @react-pdf/fontkit - so that's good I guess
here is where errors are coming from:
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)
@marybbr - don't listen to me! I'm still not sure what is going on. Looking for answers
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
[email protected] - just has this
pretty sure this is where some of the issues are coming from. any ideas on getting around this?
same issue what a nightmare.
Tried the above suggestion but still did not get it to work.