Frequently Asked Questions
This page addresses common issues and questions that users encounter when working with Fontsource.
TypeScript Errors
Cannot find module ‘@fontsource/[font-name]’ or its corresponding type declarations
If you’re encountering TypeScript errors like:
⬤⬤
sh
This is due to TypeScript’s noUncheckedSideEffects flag rejecting CSS files as having side effects. To resolve this, add ambient module declarations to your project:
Create a global TypeScript declaration file (e.g., src/globals.d.ts) and include:
⬤⬤
ts
This tells TypeScript to allow imports from CSS files and Fontsource packages without type checking.
Performance Issues
Large bundle sizes
If your bundle size is larger than expected:
- Use variable fonts: When available, variable fonts can significantly reduce bundle size compared to importing multiple static weights.
⬤⬤
jsx
- Import only needed weights: Only import the specific weights and styles you actually use.
⬤⬤
jsx
Variable Fonts
Variable font not working
If variable fonts aren’t working as expected:
- Check browser support: Ensure the target browsers support variable fonts.
- Verify font-family name: Variable fonts typically have “Variable” in their font-family name:
⬤⬤
css
- Use CSS custom properties: For variable fonts, you can use CSS custom properties or
font-variation-settings:
⬤⬤
css