#updating to 5.0
5 messages · Page 1 of 1 (latest)
Hi @waxen stump. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Astro 5.0 introduced significant changes to content collections that can cause breaking errors when upgrading from 4.8.3:
-
New Content Layer API: Astro 5.0 introduces a new Content Layer API for defining and querying content collections. This is more performant and flexible, but it changes how collections are defined and loaded. Collections now require a
loaderproperty, and thetypeproperty (contentordata) is no longer used for new collections. The config file should be moved tosrc/content.config.tsinstead ofsrc/content/config.tsContent collections, Upgrade to v5. -
Legacy Collections Are Deprecated: The old v2.0 Content Collections API is now considered legacy. While legacy collections can still work (with some limitations), you are encouraged to migrate to the new API. If you cannot migrate immediately, you can enable the
legacy.collectionsflag in yourastro.config.mjsto keep your old collections working for now:import { defineConfig } from 'astro/config'; export default defineConfig({ legacy: { collections: true } });
-
Breaking Changes to Legacy Collections:
- Collections must now be explicitly defined in
src/content.config.ts(even if empty). - The
layoutfield is no longer supported in Markdown collection entries. - The order of entries returned by
getCollection()is now non-deterministic. - Some type changes:
getEntry()may now returnundefinedand must be checked. - The
slugfield is reserved and should not be included in your schema. - You cannot mix content and data entries in the same collection.
- Collections using the new Content Layer API (with a
loader) cannot be insrc/content/Breaking changes to legacy collections, Content and data cannot be in same collection, Content Schema should not contain slug.
- Collections must now be explicitly defined in
-
astro:content is Server-Only: The
astro:contentmodule can no longer be used on the client. You must fetch data on the server and pass it to client components via props astro:content can no longer be used on the client.
What to do:
- Migrate your collections to the new Content Layer API if possible.
- If you need more time, enable the
legacy.collectionsflag. - Update your collection definitions and schemas to comply with the new requirements.
- Check for and resolve any errors about mixed content/data, reserved fields, or missing collection definitions.