brillout / vite-plugin-mdx

Vite Plugin for MDX
MIT License
113 stars 36 forks source link

Issue with MDX V2 #46

Closed tonai closed 2 years ago

tonai commented 2 years ago

Hello, I am unable to make this lib works with MDX V2.

I followed the Readme and did the following steps:

But then when I run npm run dev, I have the following error:

error when starting dev server:
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/tocab/Projects/Tmp/vite-mdx-2/node_modules/@mdx-js/mdx/index.js from /home/tocab/Projects/Tmp/vite-mdx-2/node_modules/vite-plugin-mdx/dist/imports.js not supported.
Instead change the require of index.js in /home/tocab/Projects/Tmp/vite-mdx-2/node_modules/vite-plugin-mdx/dist/imports.js to a dynamic import() which is available in all CommonJS modules.
    at Object.requireMdx (/home/tocab/Projects/Tmp/vite-mdx-2/node_modules/vite-plugin-mdx/dist/imports.js:10:12)
    at Object.createTransformer (/home/tocab/Projects/Tmp/vite-mdx-2/node_modules/vite-plugin-mdx/dist/transform.js:16:27)
    at Object.configResolved (/home/tocab/Projects/Tmp/vite-mdx-2/node_modules/vite-plugin-mdx/dist/index.js:46:43)
    at /home/tocab/Projects/Tmp/vite-mdx-2/node_modules/vite/dist/node/chunks/dep-76613303.js:74807:127
    at Array.map (<anonymous>)
    at resolveConfig (/home/tocab/Projects/Tmp/vite-mdx-2/node_modules/vite/dist/node/chunks/dep-76613303.js:74807:35)
    at async createServer (/home/tocab/Projects/Tmp/vite-mdx-2/node_modules/vite/dist/node/chunks/dep-76613303.js:60309:20)
    at async CAC.<anonymous> (/home/tocab/Projects/Tmp/vite-mdx-2/node_modules/vite/dist/node/cli.js:688:24)

I also tried to add "type": "module" in package.json without success.

Here is the minimum reproducible repo: https://github.com/tonai/vite-mdx-2

Does someone know what I am missing ? Thanks,

silvenon commented 2 years ago

Read the first paragraph of the readme:

Vite plugin to use MDX v1 with your Vite app. For MDX v2 use @mdx-js/rollup instead, this comment explains how to implement it.

😉

tonai commented 2 years ago

Sorry I did see that -_- I tryed and I'm still having trouble to run @mdx-js/rollup but that's not related to this lib anymore. Thanks for the info and sorry again

silvenon commented 2 years ago

No problem, feel free to share the error in my Twitter DM if you didn't manage to find the solution yet.