withastro/astro · error · AstroError
FileParserNotFound
FileParserNotFound
Error message
No parser was found for '${fileName}'. Pass a parser function (e.g. `parser: csv`) to the `file` loader. What it means
Thrown by the file() loader constructor when the fileName's extension is not one of the built-in supported types (json, yml, yaml, toml) and no custom parser function was supplied via options.parser. The loader needs a parser to convert file text into structured data and refuses to guess.
Source
Thrown at packages/astro/src/content/loaders/file.ts:46
}
let parse: ((text: string) => any) | null = null;
const ext = fileName.split('.').at(-1);
if (ext === 'json') {
parse = JSON.parse;
} else if (ext === 'yml' || ext === 'yaml') {
parse = (text) =>
yaml.load(text, {
filename: fileName,
});
} else if (ext === 'toml') {
parse = toml.parse;
}
if (options?.parser) parse = options.parser;
if (parse === null) {
throw new AstroError({
...FileParserNotFound,
message: FileParserNotFound.message(fileName),
});
}
async function syncData(filePath: string, { logger, parseData, store, config }: LoaderContext) {
let data: Array<Record<string, unknown>> | Record<string, Record<string, unknown>>;
try {
const contents = await fs.readFile(filePath, 'utf-8');
data = await parse!(contents);
} catch (error: any) {
logger.error(`Error reading data from ${fileName}`);
logger.debug(error.message);
return;
}
const normalizedFilePath = posixRelative(fileURLToPath(config.root), filePath);View on GitHub (pinned to d081033d5f)
Solutions
- Provide a custom parser in the options: file('data.csv', { parser: (text) => parseCsv(text) }).
- Convert your data to a supported format (json/yaml/toml) so the built-in parser applies.
- Ensure the fileName has a recognizable extension and is spelled correctly.
Example fix
// before
defineCollection({ loader: file('data.csv') });
// after
import { parse as parseCsv } from 'csv-parse/sync';
defineCollection({
loader: file('data.csv', { parser: (text) => parseCsv(text, { columns: true }) })
}); Defensive patterns
Strategy: validation
Validate before calling
const BUILTIN_EXTS = new Set(['json','yml','yaml','toml']);
function ensureParser(fileName: string, parser?: Function) {
const ext = fileName.split('.').at(-1);
if (!parser && !BUILTIN_EXTS.has(ext ?? '')) {
throw new Error(`No built-in parser for .${ext}; pass options.parser to file().`);
}
} Type guard
const hasBuiltinParser = (ext?: string) => !!ext && ['json','yml','yaml','toml'].includes(ext);
Prevention
- Pass options.parser for any non-json/yaml/toml format.
- Centralize parser choices for unusual formats in a shared helper.
- Document supported extensions for contributors.
When it happens
Trigger: Calling file('data.csv') or file('data.xml') without providing a parser option; calling file() on a file with no extension; a typo in the extension that doesn't match any built-in handler.
Common situations: Loading CSV, XML, TSV, or custom text formats without passing a parser; renaming a data file and forgetting to add a parser; new file formats the built-in set doesn't cover.
Related errors
- FileGlobNotSupported
- Glob patterns cannot start with `/`. Set the `base` option t
- Live content collections must be defined in "src/live.config
- Collection loader for ${name} does not have a load method
- ContentLoaderReturnsInvalidId
AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12).
Data as JSON: /api/errors/c16b487525174a5a.
Report an issue: GitHub.