{"record":{"id":"2428c30903e86dfb","repo":"withastro/astro","slug":"fileglobnotsupported","errorCode":"FileGlobNotSupported","errorMessage":"Glob patterns are not supported in the `file` loader. Use the `glob` loader instead.","messagePattern":"Glob patterns are not supported in the `file` loader\\. Use the `glob` loader instead\\.","errorType":"error_code","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/content/loaders/file.ts","lineNumber":31,"sourceCode":"\ntype ParserOutput = Record<string, Record<string, unknown>> | Array<Record<string, unknown>>;\n\ninterface FileOptions {\n\t/**\n\t * the parsing function to use for this data\n\t * @default JSON.parse or yaml.load, depending on the extension of the file\n\t * */\n\tparser?: (text: string) => Promise<ParserOutput> | ParserOutput;\n}\n\n/**\n * Loads entries from a JSON file. The file must contain an array of objects that contain unique `id` fields, or an object with string keys.\n * @param fileName The path to the JSON file to load, relative to the content directory.\n * @param options Additional options for the file loader\n */\nexport function file(fileName: string, options?: FileOptions): Loader {\n\tif (fileName.includes('*')) {\n\t\tthrow new AstroError(FileGlobNotSupported);\n\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) {","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/withastro/astro/blob/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/astro/src/content/loaders/file.ts#L13-L49","documentation":"The `file()` content loader reads exactly one file (JSON, YAML, TOML, or custom-parsed). Passing a filename containing `*` means you are describing multiple files, which file() cannot do, so it throws FileGlobNotSupported at config-load time and points you to the `glob()` loader.","triggerScenarios":"`defineCollection({ loader: file('src/content/blog/*.json') })` or any fileName argument containing a `*` character.","commonSituations":"Migrating from the legacy content collections API or from a glob loader and mixing up the two; wanting 'all JSON files in a directory' and reaching for file() out of habit.","solutions":["Switch to the glob loader: `glob({ pattern: '**/*.json', base: './src/content/blog' })`.","Or point file() at one concrete file: `file('src/content/blog/posts.json')`."],"exampleFix":"// before\nconst Blog = defineCollection({ loader: file('src/content/blog/*.json') });\n\n// after\nimport { glob } from 'astro/loaders';\nconst Blog = defineCollection({\n  loader: glob({ pattern: '**/*.json', base: './src/content/blog' }),\n});","handlingStrategy":"validation","validationCode":"import { file, glob } from 'astro/loaders';\n\nconst patternLike = (name: string) => name.includes('*');\nconst loader = patternLike('src/content/blog/*.json')\n  ? glob({ pattern: 'blog/**/*.json' })\n  : file('src/content/blog.json');","typeGuard":"const isSingleFileName = (name: string): boolean => !name.includes('*');","tryCatchPattern":null,"preventionTips":["Remember file() = exactly one file; glob() = many files.","Keep loader choice in one place per collection so switching is a one-line change."],"tags":["content-collections","file-loader","glob","config"],"backgroundTag":"glob-pattern-misuse","analyzedSha":"52e6c34790cc8ac4e69e6135ace06049867e5c4a","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}