withastro/astro · error · AstroError
CannotDetermineWeightAndStyleFromFontFile
CannotDetermineWeightAndStyleFromFontFile
Error message
An error occurred while determining the `weight` and `style` from local family "${family}" font file: ${url}. What it means
Thrown by FontaceFontFileReader.extract when the fontace library cannot parse a local font file to derive its weight and style. The reader does a synchronous readFileSync(url) and passes the buffer to fontace; if fontace throws (corrupt or unrecognized font), the error is wrapped as CannotDetermineWeightAndStyleFromFontFile with the family and url.
Source
Thrown at packages/astro/src/assets/fonts/infra/fontace-font-file-reader.ts:16
import { readFileSync } from 'node:fs';
import { fontace } from 'fontace';
import { AstroError, AstroErrorData } from '../../../core/errors/index.js';
import type { FontFileReader } from '../definitions.js';
import type { Style } from '../types.js';
export class FontaceFontFileReader implements FontFileReader {
extract({ family, url }: { family: string; url: string }): { weight: string; style: Style } {
try {
const data = fontace(readFileSync(url));
return {
weight: data.weight,
style: data.style as Style,
};
} catch (cause) {
throw new AstroError(
{
...AstroErrorData.CannotDetermineWeightAndStyleFromFontFile,
message: AstroErrorData.CannotDetermineWeightAndStyleFromFontFile.message(family, url),
},
{ cause },
);
}
}
}
View on GitHub (pinned to d081033d5f)
Solutions
- Confirm the file at url is a valid, complete font (open it in a font tool or re-download).
- Verify the path is correct and points to the intended .woff/.woff2/.ttf/.otf file.
- Provide explicit weight and style in the font config so extraction is not required.
- Re-download the font from the original source to rule out truncation.
- Inspect the `cause` to see fontace's specific parse error.
Example fix
// before
{ family: 'MyFont', src: [local('MyFont')] }
// after - specify weight/style explicitly to bypass extraction
{ family: 'MyFont', weight: 700, style: 'normal', src: [local('MyFont-Bold')] } Defensive patterns
Strategy: validation
Validate before calling
import { existsSync, statSync } from 'node:fs';
function isValidLocalFont(url: string): boolean {
return existsSync(url) && statSync(url).size > 0;
} Try / catch
try { reader.extract({ family, url }); }
catch (e) {
if (e instanceof AstroError && e.code === 'CannotDetermineWeightAndStyleFromFontFile') {
// fall back to explicit weight/style from config
}
} Prevention
- Always specify weight and style explicitly for local fonts to bypass extraction.
- Validate local font files are non-empty and parseable before build.
- Keep font sources under version control to detect corruption.
When it happens
Trigger: Calling extract({ family, url }) on a local font file that is not a valid parseable font (e.g. a .txt renamed to .woff2), a truncated/corrupt binary, or an unsupported font container that fontace cannot introspect. Also thrown if readFileSync itself fails before fontace runs.
Common situations: User points a local() source at the wrong file, a font downloaded incompletely, a license/placeholder file, or a font format fontace does not yet support. Typically surfaces during astro build while resolving local families.
Related errors
- UnknownFilesystemError
- UnknownFilesystemError
- CannotFetchFontFile
- CannotExtractFontType
- UnknownFilesystemError
AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12).
Data as JSON: /api/errors/cfbf053143ced1d0.
Report an issue: GitHub.