🔥 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: Collection Contains Entries of a Different Type

Fix "collection contains entries of a different type" in Astro: split Markdown and JSON files into separate folders, or move the collection to a glob() loader.

#Astro#Errors#Content Collections

“Collection contains entries of a different type.” means a legacy folder-based collection holds files that don’t match its declared type: JSON or YAML files in a type: 'content' collection, or Markdown in a type: 'data' one. The message reads ““authors” contains data entries, but is configured as a content collection.” Either move the stray files to their own folder, or, better, define the collection with a glob() loader so its pattern decides exactly which files it includes.

Key Takeaways

  • The type check applies to collections that still declare a legacy type. Loader-based collections have no type to mismatch.
  • Content entries are .md/.mdx; data entries are .json/.yaml/.toml. Legacy collections can’t mix them.
  • The sibling error “Content and data cannot be in same collection.” has the same fix.
  • Keep data files out of Markdown folders in src/content/, for example in src/data/, and load them with file().

What the messages mean

Title Message
Collection contains entries of a different type. "authors" contains data entries, but is configured as a content collection.
Content and data cannot be in same collection. “blog” contains a mix of content and data entries. All entries must be of the same type.

For the first, Astro adds the hint “Try adding type: 'data' to your collection config.” when the folder holds only data files. That hint fixes the legacy setup, but the lasting fix is a loader.

Legacy collections infer each collection from a folder in src/content/, and each must hold one kind of file. A src/content/blog/ with post.md plus a series.json next to it trips the mixed-entry check, and the dev server’s file watcher can still report it for mixed folders under src/content/ after you add loaders. Separate folders avoid both.

Fix 1: move the stray files

Find files that don’t match:

# Terminal: list non-Markdown files in a content folder
find src/content/blog -type f ! -name '*.md' ! -name '*.mdx'

Move data files to their own folder and define a second collection for them. Files starting with _ are ignored by legacy collections, which also works for notes or partials you want to keep in place.

Fix 2: switch to glob() loaders

Loader-based collections don’t have a type. Each one includes exactly the files its pattern matches. Move the data file to src/data/ and load it separately:

// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob, file } 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(), series: z.string().optional() }),
});

const series = defineCollection({
  loader: file('src/data/series.json'),
  schema: z.object({ name: z.string(), description: z.string() }),
});

export const collections = { blog, series };

Here blog takes only Markdown and MDX, and series reads its entries from one JSON file. Remove any type fields while you’re there; the invalid collection type fix explains why.

Once every collection has a loader, remove legacy.collectionsBackwardsCompat from astro.config.mjs if you enabled it. Connect the two collections with reference('series') if posts point at a series; the collection references tip shows how.

After the fix

Restart the dev server so the collection list is regenerated, then run npx astro sync to refresh types. The content layer loaders guide covers loader options in depth, our content docs show the collection setup in Komal Astro themes, and the official collections guide has the full API.

FAQ

Can one Astro collection contain Markdown and JSON?

A glob() loader can match both if its pattern includes both extensions, but it’s cleaner to keep Markdown and data in separate collections and folders. Legacy folder-based collections can’t mix them at all.

What counts as a data entry in Astro?

Files parsed into plain data: .json, .yaml, .yml and .toml. Content entries are Markdown and MDX files with a body to render.

Do loader-based collections get this error?

The “different type” check needs a legacy type field, so it doesn’t apply to loader collections. Keeping Markdown and data files in separate folders also avoids the mixed-entry warning from the dev server’s watcher.