Closed kirill-konshin closed 1 year ago
same here
https://github.com/vercel/next.js/issues/43656#issuecomment-1445971059
Currently mdxRs
does not support plugins. You can set mdxRs: false
in the next.config.mjs
if you want to use the plugins.
Also if you set mdxRs: false
you should install @mdx-js/loader
. Otherwise nextjs server(both development and production) won't start.
Thanks. If so, this official code example is wrong ? https://beta.nextjs.org/docs/guides/mdx#remark-and-rehype-plugins
import addMdx from '@next/mdx';
addMdx(nextConfig, {
options: {
remarkPlugins: [],
rehypePlugins: [],
// If you use `MDXProvider`, uncomment the following line.
// providerImportSource: "@mdx-js/react",
}
})
export default {
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'mdx'],
experimental: {
appDir: true,
mdxRs: true,
}
}
@pokuwagata is right, docs need to be fixed. Additionally, docs don't mention that @mdx-js/loader
has to be installed manually, without it next dev
silently fails.
I tried mdxRs: false
and install @mdx-js/loader
but It seems that rehypePlugins
is not work in @next/mdx
.
const nextConfig = {
pageExtensions: ["ts", "tsx", "js", "jsx", "mdx"],
experimental: {
appDir: true,
mdxRs: false,
},
};
const withMDX = addMdx({
options: {
remarkPlugins: [],
rehypePlugins: [
() => {
console.log("⭐"); // not logged
},
rehypeHighlight, // not worked
],
},
});
export default withMDX(nextConfig);
I'm having the same issue, I'm trying to use remark-gfm
and it's not working on next@13.2.1. This is my next.config.mjs
:
import mdx from '@next/mdx'
import remarkGfm from 'remark-gfm'
const withMDX = mdx({
options: {
remarkPlugins: [remarkGfm]
}
})
/** @type {import('next').NextConfig} */
const nextConfig = {
pageExtensions: ['js', 'jsx', 'md', 'mdx'],
experimental: {
mdxRs: false
}
}
export default withMDX(nextConfig)
+1 on this
In last version (13.4.0) is working as expected
// next.config.mjs
import rehypePrettyCode from "rehype-pretty-code";
import remarkGfm from "remark-gfm";
import withMDX from "@next/mdx";
import { rehypePrettyCodeOptions, rehypePrettyCodeClasses } from "./lib/rehype.mjs";
const mdxConfig = {
options: {
remarkPlugins: [remarkGfm],
rehypePlugins: [
[rehypePrettyCode, rehypePrettyCodeOptions],
[rehypePrettyCodeClasses],
],
},
};
const nextConfig = {
pageExtensions: ["ts", "tsx", "js", "jsx", "md", "mdx"],
reactStrictMode: true,
images: {
domains: ["api.producthunt.com", "img.shields.io"],
},
experimental: {
appDir: true,
mdxRs: false,
},
};
export default withMDX(mdxConfig)(nextConfig);
I think not only version 13.4.0
but also 13.2.2
works as expected.
FYI
Although document doesn't say, next-mdx-remote
also works with remark/rehype plugins.
<MDXRemote
source={content}
components={components}
options={{
mdxOptions: {
remarkPlugins: [remarkGfm],
rehypePlugins: [rehypeHighlight],
},
}}
/>
The docs have been updated to no longer show the plugins and mdxRs flag in the same code sample. Thanks for the report!
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
MDX (@next/mdx)
Link to the code that reproduces this issue
https://codesandbox.io/p/sandbox/nextjs-mdx-plugins-ignored-4y7x8n
To Reproduce
Options provided to nextMDX are ignored:
Describe the Bug
Open the page https://4y7x8n-3000.p.csb.app
Frontmatter is not parsed, code block contains raw codeblocks without highlighting, no GFM applied:
Expected Behavior
Proper work of all plugins.
Which browser are you using? (if relevant)
Chrome
How are you deploying your application? (if relevant)
Codesandbox