#Content collection is empty after V5 migration

23 messages · Page 1 of 1 (latest)

static pasture
#

Hello! Just now migrating my site to v5 and the only real migration I need to do is a simple (or so I thought) content collection.

I've edited my src/content/config.ts to src/content.config.ts with the following setup:

import { defineCollection, z } from "astro:content";
import { glob } from "astro/loaders";

const knowledgebase = defineCollection({
  loader: glob({ pattern: "**/*.mdx", base: "./src/content/knowledgebase" }),
  schema: z.object({
    title: z.string(),
    category: z.string(),
  }),
});

export const collections = {
  knowledgebase,
};

The content hasn't moved, it's still src/content/knowledgebase but no matter how I adjust the glob I get the following:

The collection "knowledgebase" does not exist or is empty. Ensure a collection directory with this name exists.

Unsure of how to fix this tbh, any help is appreciated!

PS. V5 looks awesome 😄

lunar cairn
#

not sure if related but the docs seem to indicate escaping / in the glob pattern i.e. "**\/*.md"

static pasture
#

Good catch, seems like prettier doesn't agree it needs to be escaped and is removing that. But even when adding it and saving without formatting there's no change, unfortunately.

glossy island
#

Try removing the ./

static pasture
#

Yea, tried that too, still nothing I'm afraid

#

Also tried moving the folder about, including outside the src folder

#

No matter how I move it or set it up, I can't seem to get it to work

#

Also created a new folder, with a single new .md file, and adjusted the glob for that, didn't work either

glossy island
#

Okay. So a .md file wouldn’t work. As your loader is pulling .mdx

static pasture
#

Sorry, me being unclear, I tried remaking the loader with a new pattern just for that test file

glossy island
#

Ahh no worries.

#

<@&1129102257422610512> ideas on this?

frozen fable
#

I'm pretty sure you need to move your collections out of the src/content folder. I believe src/data is recommended but it could be any folder in src. The content folder is now only for legacy conten collections. I'm pretty sure I saw this in the original instructions for migration to the content layer on Astro 4, but I can't see them in the v5 docs 🤔

#

But I just noticed that you said you tried moving the folder 🤔

quartz forge
#

Have you tried to delete your .astro directory? I'm not yet on v5 but with the experimental feature on v4 sometimes this was fixing my issues... (the directory is regenerated when you run the dev command)

#

So I guess with a major update, the cache needs to be cleaned...

lunar meadow
static pasture
static pasture
static pasture
#

And really appreciate all the responses 😄

static pasture
#

Finally had a chance to try, deleting the .astro directory and then re-running again seems to have fixed it. I probably deleted it right at the start but not after I actually did the content collection migration fully.

Appreciate all the help!

hidden oceanBOT
#
If your issue is resolved, please help by doing the following two steps:
  1. From the ellipses (3-dot menu) in the top-right corner of the post (not the first message), edit the tags to include the Solved tag.
  2. From the same ellipses, select Close Post.
    Your post will still be available to search and can be re-opened simply by replying in it. Closing a post moves it down with older posts, so we can more easily focus on issues that still need to be resolved.
    Thank you for your help!