🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Content & MDX••By Komal Nakrani

Fix: Astro Collection Has an Invalid type Field

Fix the Astro collection invalid type error: remove type: 'content' or 'data' from defineCollection() and replace it with a glob() or file() loader in Astro 7.

#Astro#Errors#Content Collections#Upgrade

The Astro collection invalid type error means a collection in src/content.config.ts still has a type field, such as type: 'content' or type: 'data', from the old collections API. Astro’s catalogue lists it as “Content collection has an invalid type field.” with the message “Invalid collection type “content”. Remove the type from your collection definition in src/content.config.ts.” Delete type and give the collection a loader instead: glob() for a folder of files, file() for one data file.

Key Takeaways

  • type belongs to legacy collections. Current collections are defined by their loader.
  • type: 'content' becomes glob() with a Markdown or MDX pattern.
  • type: 'data' becomes glob() with a JSON or YAML pattern, or file() for a single file.
  • In Astro 7, type next to a loader throws a “legacy features” error; type without a loader leaves the collection empty.

What you’ll see in Astro 7

Depending on the definition, current releases report the problem in one of two ways.

With both type and loader, defineCollection() throws:

A content collection is defined with legacy features (e.g. missing a `loader` or has a `type`).
Check your collection definitions in src/content.config.ts to ensure that all collections
are defined using the current properties.

With type and no loader, the collection is skipped and getCollection() logs:

The collection "blog" does not exist or is empty. Please check your content config file for errors.

Both come from the same cause, and the fix below handles either.

The fix: replace type with a loader

Before:

// src/content.config.ts
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';

const blog = defineCollection({
  type: 'content',
  schema: z.object({ title: z.string(), pubDate: z.date() }),
});

const authors = defineCollection({
  type: 'data',
  schema: z.object({ name: z.string() }),
});

export const collections = { blog, authors };

After:

// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';

const blog = defineCollection({
  loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: './src/content/blog' }),
  schema: z.object({ title: z.string(), pubDate: z.coerce.date() }),
});

const authors = defineCollection({
  loader: glob({ pattern: '**/*.{json,yaml}', base: './src/content/authors' }),
  schema: z.object({ name: z.string() }),
});

export const collections = { blog, authors };

Keep the files where they are; base points the loader at the old folders. If all authors live in one file, use file('src/data/authors.json') instead. The z import also moves to astro/zod, since the astro:content export is deprecated.

Update the code that reads the collection

Legacy type: 'content' entries had a slug and a render() method. Loader-based entries don’t:

  • Replace entry.slug with entry.id in links and getStaticPaths().
  • Replace await entry.render() with await render(entry), importing render from astro:content.
  • Replace getEntryBySlug() and getDataEntryById() with getEntry().

If the collection config is still at src/content/config.ts, move it to src/content.config.ts. The legacy content config fix covers that step, and content collection is missing a loader covers the related error.

Short-term workaround

legacy.collectionsBackwardsCompat: true in astro.config.mjs keeps old folder-based collections working while you migrate. Treat it as temporary and remove it once each collection has a loader.

The content collections guide has a full migration checklist, and our content docs show the loader setup used in Komal Astro themes. The official upgrade notes on legacy collections list every change.

FAQ

What replaced type: ‘content’ in Astro?

A glob() loader with a Markdown or MDX pattern, for example glob({ pattern: '**/*.md', base: './src/content/blog' }).

Can I still use type: ‘data’?

No. Use glob() with a JSON or YAML pattern for a folder of data files, or file() for a single file holding many entries.

Why is my collection empty after upgrading?

A collection with type and no loader is skipped, so getCollection() returns nothing and logs that the collection is empty. Add a loader and restart the dev server.