Fix Astro 'Duplicate id found' content warning
If you see a warning like this during build:
[glob-loader] Duplicate id \"your-post-slug\" found in ...
you are usually dealing with one of two issues:
- duplicate files/slugs in
src/content/blog - stale generated content cache after renames or rapid edits
Here is the fastest way to fix it reliably.
Step 1: verify there is only one file per slug
Check your blog content directory for lookalike filenames:
ls -la src/content/blog
Things to watch for:
- same slug in
.mdand.mdx - accidental copy like
post copy.md - case-only differences (
Post.mdvspost.md)
Step 2: clear Astro content cache
When files were renamed/moved, stale cache is common.
rm -rf .astro
npm run build
If the warning disappears, cache was the issue.
Step 3: restart a single dev server
Multiple astro dev instances on different ports can make warnings seem random.
pkill -f "astro dev" || true
pkill -f "npm run dev" || true
npm run dev
Step 4: keep slug generation simple
Use one post per file and keep filenames unique and lowercase:
fix-worker-env-vars.mdastro-contact-form-turnstile.md
Avoid spaces and punctuation-heavy names.
Why this works
Astro content IDs are derived from content file paths/slugs. Duplicate sources or stale cache state causes collisions. Cleaning files + cache removes both failure modes.
If this warning appears in CI only, add a clean build step in CI (remove .astro before build) to match local behavior.