withastro/astro · error · AstroError
FileGlobNotSupported
FileGlobNotSupported
Error message
Glob patterns are not supported in the `file` loader. Use the `glob` loader instead.
What it means
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.
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')`.
Example fix
// before
const Blog = defineCollection({ loader: file('src/content/blog/*.json') });
// after
import { glob } from 'astro/loaders';
const Blog = defineCollection({
loader: glob({ pattern: '**/*.json', base: './src/content/blog' }),
}); Defensive patterns
Strategy: validation
Validate before calling
import { file, glob } from 'astro/loaders';
const patternLike = (name: string) => name.includes('*');
const loader = patternLike('src/content/blog/*.json')
? glob({ pattern: 'blog/**/*.json' })
: file('src/content/blog.json'); Type guard
const isSingleFileName = (name: string): boolean => !name.includes('*'); Prevention
- Remember file() = exactly one file; glob() = many files.
- Keep loader choice in one place per collection so switching is a one-line change.
When it happens
Trigger: `defineCollection({ loader: file('src/content/blog/*.json') })` or any fileName argument containing a `*` character.
Common situations: 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.
Related errors
- Auto-generating collections for folders in "src/content/"…
- ** ** contains multiple entries with the same slug: ` `…
- Content config not loaded
- DuplicateContentEntrySlugError
- FileParserNotFound
AI-assisted analysis of withastro/astro@52e6c34790 (2026-08-18).
Data as JSON: /api/errors/2428c30903e86dfb.
Report an issue: GitHub.
Appendix: source
Thrown at packages/astro/src/content/loaders/file.ts:31
type ParserOutput = Record<string, Record<string, unknown>> | Array<Record<string, unknown>>;
interface FileOptions {
/**
* the parsing function to use for this data
* @default JSON.parse or yaml.load, depending on the extension of the file
* */
parser?: (text: string) => Promise<ParserOutput> | ParserOutput;
}
/**
* 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.
* @param fileName The path to the JSON file to load, relative to the content directory.
* @param options Additional options for the file loader
*/
export function file(fileName: string, options?: FileOptions): Loader {
if (fileName.includes('*')) {
throw new AstroError(FileGlobNotSupported);
}
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) {View on GitHub (pinned to 52e6c34790)