{"record":{"id":"c16b487525174a5a","repo":"withastro/astro","slug":"fileparsernotfound","errorCode":"FileParserNotFound","errorMessage":"No parser was found for '${fileName}'. Pass a parser function (e.g. `parser: csv`) to the `file` loader.","messagePattern":"No parser was found for '(.+?)'\\. Pass a parser function \\(e\\.g\\. `parser: csv`\\) to the `file` loader\\.","errorType":"error_code","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/content/loaders/file.ts","lineNumber":46,"sourceCode":"\t}\n\n\tlet parse: ((text: string) => any) | null = null;\n\n\tconst ext = fileName.split('.').at(-1);\n\tif (ext === 'json') {\n\t\tparse = JSON.parse;\n\t} else if (ext === 'yml' || ext === 'yaml') {\n\t\tparse = (text) =>\n\t\t\tyaml.load(text, {\n\t\t\t\tfilename: fileName,\n\t\t\t});\n\t} else if (ext === 'toml') {\n\t\tparse = toml.parse;\n\t}\n\tif (options?.parser) parse = options.parser;\n\n\tif (parse === null) {\n\t\tthrow new AstroError({\n\t\t\t...FileParserNotFound,\n\t\t\tmessage: FileParserNotFound.message(fileName),\n\t\t});\n\t}\n\n\tasync function syncData(filePath: string, { logger, parseData, store, config }: LoaderContext) {\n\t\tlet data: Array<Record<string, unknown>> | Record<string, Record<string, unknown>>;\n\n\t\ttry {\n\t\t\tconst contents = await fs.readFile(filePath, 'utf-8');\n\t\t\tdata = await parse!(contents);\n\t\t} catch (error: any) {\n\t\t\tlogger.error(`Error reading data from ${fileName}`);\n\t\t\tlogger.debug(error.message);\n\t\t\treturn;\n\t\t}\n\n\t\tconst normalizedFilePath = posixRelative(fileURLToPath(config.root), filePath);","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/content/loaders/file.ts#L28-L64","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ndefineCollection({ loader: file('data.csv') });\n// after\nimport { parse as parseCsv } from 'csv-parse/sync';\ndefineCollection({\n  loader: file('data.csv', { parser: (text) => parseCsv(text, { columns: true }) })\n});","handlingStrategy":"validation","validationCode":"const BUILTIN_EXTS = new Set(['json','yml','yaml','toml']);\nfunction ensureParser(fileName: string, parser?: Function) {\n  const ext = fileName.split('.').at(-1);\n  if (!parser && !BUILTIN_EXTS.has(ext ?? '')) {\n    throw new Error(`No built-in parser for .${ext}; pass options.parser to file().`);\n  }\n}","typeGuard":"const hasBuiltinParser = (ext?: string) => !!ext && ['json','yml','yaml','toml'].includes(ext);","tryCatchPattern":null,"preventionTips":["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."],"tags":["content-collections","loader","file-loader","parser","config-mistake"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}