@react-pdf/font: published types import fontkit, but @types/fontkit is only a devDependency

Open Beginner friendly
#3,592 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@iliev-blnk is already working on this.

Since Oct 22, 2026.

  • #3602 by @iliev-blnk — open

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/font 4.1.2 (also on main), @react-pdf/textkit 7.0.1, through @react-pdf/renderer 4.9.0
Dominant language
TypeScript
Stars
16.9k
Forks
1.3k
Avg merge
11m
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from diegomura/react-pdf

All issues in diegomura/react-pdf

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.