Next.js Discord

Discord Forum

Using mdx

Unanswered
Shaurya posted this in #help-forum
Open in Discord
I followed all the steps in the docs to use mdx

first installed all the deps
npm install @next/mdx @mdx-js/loader @mdx-js/react @types/mdx

then confirgured the next config file
import createMDX from "@next/mdx"

/** @type {import("next").NextConfig} */

const nextConfig = {
  pageExtensions: ["js", "jsx", "md", "mdx", "ts", "tsx"],
}

const withMDX = createMDX({})

export default withMDX(nextConfig)

then added the mdx components file in the root of my project
mdx-components.tsx:
import type { MDXComponents } from 'mdx/types'
 
export function useMDXComponents(components: MDXComponents): MDXComponents {
  return {
    ...components,
  }
}

then after all that I tried using mdx

content.mdx:
---
title: "tos content"
---

terms of service content

page.tsx:
import Content from "./content.mdx"
import styles from "styles/legal/tos.module.css"

export default function TOS() {

  return (
    <div className={styles.container}>
      <div>
        Terms of Service
      </div>
      <Content />
    </div>
  )
}

but an error rises and it says:
⨯ ReferenceError: Content is not defined
    at TOS (project\.next\server\chunks\[root of the server]__2da40a._.js:773:270)
    at stringify (<anonymous>)

7 Replies

can anyone please help me out with this
Please only bump once a day. Do not delete the bump message then rebump.
@joulev Please only bump once a day. Do not delete the bump message then rebump.
oh, sure, it went very down so did it
do you've any idea why isn't this working though, I followed all the steps in the docs properly
but it just says Content is not defined when I just imported it there
anyone please help :please_cat: 🙏🏻
been stuck on this problem for more than a day, I've did all the things step by step as said in docs
but it just says Content is not defined but I just imported it there
i think its still very hard to help with this much info. a minimal reproduction repo will help