Skip to content

Feature request: Warn when .md files contain ESM imports (should be .mdx) #14966

@schickling

Description

@schickling

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:

  1. Warn the user that the file should be renamed to .mdx, or
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageIssue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions