TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/shuding/nextra/llms.txt
Use this file to discover all available pages before exploring further.
mdx-components file is the central place to customize how standard Markdown elements — headings, links, images, code blocks, and more — are rendered throughout your Nextra site. By exporting a single useMDXComponents function from this file, you can override any HTML element with your own React component globally, without touching individual MDX pages.
Why This File Exists
When@mdx-js/mdx compiles an MDX file, it resolves component overrides through an import path aliased as next-mdx-import-source-file. Nextra maps that alias to your mdx-components file, so every compiled MDX page automatically picks up your overrides. This is the same mechanism used by Next.js’s official @next/mdx package, extended by Nextra for its own defaults (image zoom, syntax highlighting, anchor links, etc.).
File Location
Themdx-components file can live at the project root or inside src/:
Required Export
The file must export a function nameduseMDXComponents. This function receives the components passed in by the current MDX context and returns the merged component map:
mdx-components.ts
Overriding Elements
Spread the theme’s defaults and then add your own overrides. Any standard HTML tag name is a valid key:mdx-components.tsx
Always spread the theme’s components (
...getNextraMDXComponents(components) or ...themeComponents) first. Placing your overrides after the spread ensures they take precedence without discarding Nextra’s built-in enhancements.How Next.js Resolves the File
Nextra sets up a module aliasnext-mdx-import-source-file that points to your mdx-components file. This alias is declared in Nextra’s type definitions:
useMDXComponents from next-mdx-import-source-file, which resolves to your project’s mdx-components file. This wiring happens automatically — no manual alias configuration is needed for webpack builds.
Turbopack: Fixing the next-mdx-import-source-file Error
When using Turbopack, the automatic alias resolution may not be configured. If you see:
next.config.mjs:
- Next.js ≥ 15.3
- Next.js < 15.3
next.config.mjs
Avoiding False ESLint Positives
The React Hooks ESLint plugin treats any function whose name starts withuse as a hook and warns if you call it at the module’s top level. To avoid this false positive when importing useMDXComponents, alias it on import:
mdx-components.tsx
Using src/ Directory
If your project uses a src/ layout, move mdx-components into src/:
src/mdx-components automatically, the same way it detects src/content. Remember to update the Turbopack resolveAlias path if you’re using Turbopack.