{"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":27,"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":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/content/loaders/file.ts#L9-L45","documentation":"Thrown synchronously by the file() loader constructor when the supplied fileName contains a '*' character. The file() loader reads a single concrete file; glob matching is the responsibility of the separate glob() loader, so the API refuses to silently misinterpret a glob pattern as a literal filename.","triggerScenarios":"Calling file('data/*.json') or file('**/config.yaml') — i.e. passing a glob pattern (containing *) as the fileName argument to the file() loader instead of using the glob() loader.","commonSituations":"Mistakenly importing { file } instead of { glob } from 'astro/loaders'; copying a glob pattern from elsewhere into a file() call; intending to load multiple files but picking the wrong loader.","solutions":["Switch to the glob() loader: import { glob } from 'astro/loaders' and use glob({ pattern: '...', base: ... }).","If you meant a single file, remove the '*' from the path and pass a concrete filename to file()."],"exampleFix":"// before\nimport { file } from 'astro/loaders';\ndefineCollection({ loader: file('data/*.json') });\n// after\nimport { glob } from 'astro/loaders';\ndefineCollection({ loader: glob({ pattern: 'data/*.json' }) });","handlingStrategy":"type-guard","validationCode":"// Before calling file(), ensure the path is concrete\nfunction assertConcreteFile(name: string) {\n  if (name.includes('*')) throw new Error(`Use glob() for patterns; file() got ${name}`);\n}","typeGuard":"const isGlobPattern = (p: string) => /[*?!]/.test(p) || p.includes('/**') || p.includes('{');","tryCatchPattern":null,"preventionTips":["Reserve file() for a single concrete filename; reach for glob() for patterns.","Lint content-config files for file() calls whose first arg contains '*'.","Keep a cheat-sheet: file = one file, glob = many files."],"tags":["content-collections","loader","file-loader","config-mistake"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}