{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
@@ -26,6 +26,18 @@ Next.js can support both local MDX content inside your application, as well as r
> **Good to know**: View the [Portfolio Starter Kit](https://vercel.com/templates/next.js/portfolio-starter-kit) template for a complete working example.
<AppOnly>
> **Good to know**: If you want to return Markdown from a rendered route instead of compiling MDX to HTML, see [Markdown output](/docs/app/guides/markdown-output).
</AppOnly>
<PagesOnly>
> **Good to know**: If you want to return Markdown from a rendered route instead of compiling MDX to HTML, see [Markdown output](/docs/pages/guides/markdown-output).
</PagesOnly>
## Install dependencies
The `@next/mdx` package, and related packages, are used to configure Next.js so it can process markdown and MDX. **It sources data from local files**, allowing you to create pages with a `.md` or `.mdx` extension, directly in your `/pages` or `/app` directory.
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
description: Enable experimental Markdown output for App Router and Pages Router routes.
version: experimental
---
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
Enable experimental Markdown output for routes that opt into `text/markdown` responses.
```js filename="next.config.js"
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
markdown: true,
},
}
module.exports = nextConfig
```
## Good to know
- This flag enables the Markdown runtime, but routes must still opt in with `export const markdown = true` or `export const markdown = { components: ... }`.
- Markdown is only returned for full document `GET` and `HEAD` requests that prefer `text/markdown`.
- RSC requests, prefetch requests, and data requests keep their existing response formats.
- The feature works in both App Router and Pages Router when the route runs in the Node.js runtime.
- Edge runtime routes ignore Markdown negotiation and continue to return their normal responses.
title: How to generate Markdown output from your Next.js routes
nav_title: Markdown output
description: Learn how to have App Router and Pages Router routes return Markdown from the React tree they render.
source: app/guides/markdown-output
---
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
"1085":"Route \"%s\": Runtime data such as \\`cookies()\\`, \\`headers()\\`, \\`params\\`, or \\`searchParams\\` was accessed inside \\`generateMetadata\\` or you have file-based metadata such as icons that depend on dynamic params segments. Except for this instance, the page would have been entirely prerenderable which may have been the intended behavior. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata",
"1086":"Route \"%s\": %s This delays the entire page from rendering, resulting in a slow user experience. Learn more: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport",
"1087":"Failed to parse \"%s\":\\n%s%s",
"1088":"Expected RSC navigation response to have a body"
"1088":"Expected RSC navigation response to have a body",
"1089":"RSC fetch failed after all retry attempts",
"1090":"Markdown output is not supported in the Edge runtime."
// eslint-disable-next-line no-new-func -- We compile user-provided markdown-components modules to CommonJS and execute them in an isolated local module scope.