How to use MDX on CF Pages?

I am trying to use CF Pages for my Next.js blog. I use MDX for that. I followed the instructions from Vercel (https://nextjs.org/docs/app/building-your-application/configuring/mdx)

and this is my next.config.mjs:

import rehypePrism from '@mapbox/rehype-prism'
import nextMDX from '@next/mdx'
import remarkGfm from 'remark-gfm'

import { setupDevPlatform } from '@cloudflare/next-on-pages/next-dev'

if (process.env.NODE_ENV === 'development') {
  await setupDevPlatform()
}

/** @type {import('next').NextConfig} */
const nextConfig = {
  pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'mdx'],
  experimental: {
    mdxRs: false,
  },
}

const withMDX = nextMDX({
  extension: /\.mdx?$/,
  options: {
    remarkPlugins: [remarkGfm],
    rehypePlugins: [rehypePrism],
  },
})

export default withMDX(nextConfig)

when I use the simple next dev everything works fine. But the following error shows up If i simulate the CF Pages with the preview command (during compilation):

ERROR: Failed to produce a Cloudflare Pages build from the project.
⚡️ 
⚡️      The following routes were not configured to run with the Edge Runtime:
⚡️        - /articles/crafting
⚡️ 
⚡️      Please make sure that all your non-static routes export the following edge runtime route segment config:
⚡️        export const runtime = 'edge';


I tried to add the runtime config to the .mdx files, but It does not change anything.

this is my mdx-components.tsx:

import { type MDXComponents } from 'mdx/types'
import Image, { type ImageProps } from 'next/image'

export const runtime = 'edge'

export function useMDXComponents(components: MDXComponents) {
  return {
    ...components,
    Image: (props: ImageProps) => <Image {...props} />,
  }
}


I appreciate any kind of feedback on that. I tried to lookup old threads, but I did not found a solution to this
Was this page helpful?