I'm trying to use mdx files in Next.js 13. I've already done all the necessary configuration in next.config and created the file. Inside the app folder, I have > docs > components > accordion > page.mdx
The page file only renders a title like "# Title". When I navigate to this URL, I get the following error:
node_modules/@mdx-js/react/lib/index.js (34:26) @ React error - createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component
How could I fix this?
my next.config.js
const withMDX = require('@next/mdx')({
extension: /\.mdx?$/,
options: {
remarkPlugins: [],
rehypePlugins: [],
},
})
/** @type {import('next').NextConfig} */
const nextConfig = {
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
experimental: {
appDir: true,
},
}
module.exports = withMDX(nextConfig)