-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Summary
Astro should warn when a .md file in content collections contains ESM import statements, as these require .mdx extension to be processed correctly.
Current behavior
When a .md file contains import statements like:
---
title: My Page
---
import MyComponent from './MyComponent.tsx'
<MyComponent />
Astro silently fails to process the imports. The file is treated as plain markdown, and the import statements appear as literal text in the output (or cause cryptic errors during development).
Expected behavior
Astro should detect when a .md file contains patterns that require MDX processing (ESM imports, JSX syntax) and either:
- Warn the user that the file should be renamed to
.mdx, or - Error with a helpful message explaining the issue
A simple heuristic would be checking for lines starting with import in .md files within content collections.
Motivation
This is a common mistake when authoring documentation. The fix is trivial (rename .md → .mdx), but the error is not obvious without prior knowledge of the distinction.
Related issue: #6226 (unhelpful error messages for MDX content)
Environment
- Astro version: 5.x
- MDX integration: @astrojs/mdx
This issue was filed while implementing a workaround lint check in our project. Happy to provide more details or help with implementation.