astro 5 getCollection returns an empty array after moving my blog to glob() Astro
Upgraded a 60-post blog from Astro 4 to 5.3. Moved the collection to the content layer loader:
const blog = defineCollection({
loader: glob({ pattern: '**/*.md', base: './content/blog' }),
schema: z.object({ title: z.string(), date: z.coerce.date() })
});
Files are in src/content/blog/. getCollection('blog') returns []. No error, no warning. Build succeeds and produces an index page with zero entries, which is the worst possible failure mode.
Where do you even start debugging a loader that quietly returns nothing?
@edge_runtime_bo · 2w ago · 3 replies
baseresolves from the project root, not fromsrc/content. Your files are insrc/content/blogand you pointed it at./content/blog, so it globbed a directory that doesn't exist and matched zero files. No error because an empty glob is perfectly legal.Two follow-ups worth doing while you're there:
.astro/and re-run. The content store is cached and a stale one will keep serving you an empty collection after you've fixed the path, which is how people conclude the fix didn't workif (posts.length === 0) throw new Error('no posts')in your index page. This will happen again, and a build that silently ships an empty blog is far worse than a red buildReply
Report
@rubberduck_rae · 2w ago
That was it. And yes, I had to nuke .astro/ before it took — spent ten minutes convinced the fix hadn't worked.
Reply
Report
@tomato_tobin · 2w ago
The
.astro/cache has cost me more time than any actual Astro bug. First thing to try on anything content-layer shaped.Reply
Report