@react-pdf/font: published types import fontkit, but @types/fontkit is only a devDependency
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- build-system
Research direction
Start with the @types/fontkit entry under devDependencies in packages/font/package.json, and compare the generated lib/index.d.ts, which imports 'fontkit'. Then check packages/textkit/package.json for the same gap, including its Node types reference. Reproduce by running npx tsc -p . in a fresh project with skipLibCheck set to false. Done when that project type-checks after installing only @react-pdf/font or @react-pdf/textkit, with no extra @types install.
Written by the indexing model from the issue text.
Description
Describe the bug
@react-pdf/font's published declarations open with import * as fontkit from 'fontkit', and fontkit ships no types of its own. They come from @types/fontkit, which packages/font/package.json lists under devDependencies, so it is never installed for a consumer. A project that type-checks its dependencies' declarations (skipLibCheck: false) under strict fails on @react-pdf/font, whether it imports the package or reaches it through @react-pdf/renderer, until it adds @types/fontkit itself.
To Reproduce
A fresh project with @react-pdf/[email protected] and [email protected]:
tsconfig.json
{
"compilerOptions": {
"strict": true,
"skipLibCheck": false,
"noEmit": true,
"module": "esnext",
"moduleResolution": "bundler",
"target": "es2022"
},
"files": ["index.ts"]
}
index.ts
import FontStore from '@react-pdf/font';
new FontStore().register({ family: 'Inter', src: 'https://example.com/inter.ttf' });
npx tsc -p .
node_modules/@react-pdf/font/lib/index.d.ts(1,26): error TS7016: Could not find a declaration file for module 'fontkit'. '<project>/node_modules/fontkit/dist/browser-module.mjs' implicitly has an 'any' type.
With @types/[email protected] added to the project, the same command passes.
@react-pdf/[email protected] has the same gap, wider: its declarations import fontkit and @react-pdf/font and reference Node's types, and it declares none of them (@types/fontkit is a devDependency there too). Type-checking a project that imports one of its types:
node_modules/@react-pdf/textkit/lib/index.d.ts(1,23): error TS2688: Cannot find type definition file for 'node'.
node_modules/@react-pdf/textkit/lib/index.d.ts(2,34): error TS2307: Cannot find module 'fontkit' or its corresponding type declarations.
node_modules/@react-pdf/textkit/lib/index.d.ts(3,22): error TS2307: Cannot find module '@react-pdf/font' or its corresponding type declarations.
Expected behavior
Installing @react-pdf/font installs the types its declarations import, so it type-checks without the consumer adding @types/fontkit. Moving @types/fontkit from devDependencies to dependencies in packages/font, as TypeScript's publishing guide advises for a declaration dependency, would do it; textkit would need the same for the packages its declarations name.
Desktop
- OS: Windows 11 (a type-check failure, so not OS-specific)
- Browser: n/a
- React-pdf version:
@react-pdf/font4.1.2 (also onmain),@react-pdf/textkit7.0.1, through@react-pdf/renderer4.9.0
- Dominant language
- TypeScript
- Stars
- 16.9k
- Forks
- 1.3k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from diegomura/react-pdf
-
Unable to set flexShrink to 0Possibly taken @adarshsm claimed this 16 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
@react-pdf/hyphenate: import-only exports map throws ERR_PACKAGE_PATH_NOT_EXPORTED in require-condition resolvers (every tsx script loading renderer >= 4.7 crashes)Possibly taken @cruzdanilo claimed this 45 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
diegomura/react-pdf#3551 · 2 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
Maintainers usually reply within 1 day
All issues in diegomura/react-pdf
Similar issues
-
Waiting for: Product Owner
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
getsentry/sentry-javascript#26203 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bytedance/flowgram.ai#1235 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
devswha/herdr-web-ui#3325 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100