-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MDX v2 not working #44
Comments
The MDX v2 is published as ESM,
Next, if the ESM environment works for your project set the import mdx from "@mdx-js/rollup"
export default {
plugins: [mdx()]
} In case you need CJS see @EvHaus' solution below, #44 (comment), and if you're using React v18, see @pomber's solution, #44 (comment). If you're using React 17 or below you'll also need to alias resolve: {
alias: {
"react/jsx-runtime": "react/jsx-runtime.js"
}
}, read here for more info. I'm actually not sure if |
Thank you for your detailed explanation. It works like a charm! |
Yep! I was worried Vite won't work in ESM, but it does! |
Just wanted to add a bit more helpful info for others who venture here. I was successful with these steps:
import { defineConfig } from 'vite';
export default defineConfig(async () => {
const mdx = await import('@mdx-js/rollup');
return {
plugins: [mdx.default()]
};
});
|
Thanks for providing the code for CJS environment! I edited my comment to link to yours for people who need CJS (which is I assume most people). |
This comment was marked as off-topic.
This comment was marked as off-topic.
This is the vite config that worked for me (for React 18 + MDX v2): import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
export default defineConfig(async () => {
const mdx = await import("@mdx-js/rollup")
return {
optimizeDeps: {
include: ["react/jsx-runtime"],
},
plugins: [react(), mdx.default({ remarkPlugins: [] })],
}
}) |
@pomber thanks! I added the link to your comment in my summary comment earlier 👌 |
Notice that neither Here is a example of a full-reloading .mdx file (and how to workaround it): Here is another way to workaround it: vitejs/vite-plugin-react#38 (comment) |
Open a new issue if you have a question related to this plugin, providing details and preferrably a demo repository if your situation is complex. |
Hello,
If I install the
@mdx-js/mdx
package and follow the instructions in README.md, everything works well.However, if I use the
@mdx-js/mdx@next
package, an error would occur:The text was updated successfully, but these errors were encountered: