“Astro.glob() did not match any files” means the glob pattern you passed returned zero files. The message reads “Astro.glob(./posts/*.md) did not return any matching files.” and the hint is “Check the pattern for typos.” Almost always the path is relative to the wrong folder or the extension doesn’t match. On Astro 7 you won’t see this exact error, because Astro.glob() itself has been removed; the fix there is to switch to import.meta.glob() or a content collection.
Key Takeaways
- Glob patterns are relative to the file that calls them, not to the project root.
- Check the extension:
*.mddoesn’t match.mdxfiles.Astro.glob()is gone from current Astro. Useimport.meta.glob()for files andgetCollection()for content.import.meta.glob()returns an empty object instead of throwing, so check the result yourself.
Why the pattern matched nothing
Given this page:
---
// src/pages/blog/index.astro
const posts = await Astro.glob('./posts/*.md');
---
./posts/ resolves to src/pages/blog/posts/. If your files live in src/content/posts/, the pattern needs ../../content/posts/*.md. The other usual causes:
- The files are
.mdxbut the pattern says*.md. Use*.{md,mdx}. - Files sit in subfolders.
*matches one level; use**/*.mdfor nested folders. - A typo or letter-case mismatch in the folder name, which can pass on macOS and fail on a Linux build server.
- The pattern is built from a variable. Glob patterns must be static string literals so the bundler can analyse them.
Fix on Astro 7: use import.meta.glob()
import.meta.glob() is the Vite feature Astro.glob() was built on. With eager: true it returns modules directly:
---
// src/pages/blog/index.astro
const modules = import.meta.glob('../../content/posts/*.{md,mdx}', { eager: true });
const posts = Object.values(modules);
if (posts.length === 0) {
throw new Error('No posts found. Check the glob path in src/pages/blog/index.astro');
}
---
<ul>
{posts.map((post: any) => <li>{post.frontmatter.title}</li>)}
</ul>
Unlike Astro.glob(), an empty match returns {} without complaint. The explicit check above keeps the old fail-fast behaviour. The import.meta.glob tip covers lazy loading and raw imports.
Better fix: a content collection
For Markdown and MDX content, a collection gives you schema validation, typed frontmatter and sorting helpers:
// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const posts = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/posts' }),
schema: z.object({ title: z.string(), pubDate: z.coerce.date() }),
});
export const collections = { posts };
Here base is relative to the project root, which removes the “relative to which file?” confusion. If the folder is empty or the path is wrong, getCollection('posts') logs “The collection “posts” does not exist or is empty. Please check your content config file for errors.”
The broader migration is in Astro.glob() errors and replacements, and the content collections guide goes deeper. Our content docs show the config used in Komal Astro themes, and Vite’s glob import docs explain the pattern syntax.
FAQ
Is the Astro.glob() path relative to the project root?
No. It’s relative to the file that calls it. ./posts/*.md in src/pages/index.astro looks in src/pages/posts/.
Why does Astro.glob() work locally but fail on my host?
Usually letter case. macOS ignores case by default and Linux doesn’t, so Posts/ and posts/ are different folders on most build servers.
What replaces Astro.glob() in Astro 7?
import.meta.glob() for importing files, and content collections with getCollection() for Markdown, MDX and data.