-
Notifications
You must be signed in to change notification settings - Fork 107
Doesn't work in project that depends on MDX 2 #234
Description
I have a project that I'm trying to upgrade to MDX 2 (where I use MDX outside of Storybook)
🐞 Minimal reproduced test case here
After yarn installing, my node_modules
looks like this:
node_modules/
@mdx-js/
mdx/ (2.0.0, the one my project explicitly depends on)
storybook-builder-vite/
node_modules/
@mdx-js/
mdx/ (1.6.22, the one storybook-builder-vite and vite-plugin-mdx depend on)
vite-plugin-mdx/
dist/
imports.js (the source of the error)
I think that should be fine. storybook-builder-vite and vite-plugin-mdx should find 1.6.22 because dependency resolution.
But vite-plugin-mdx is actually attempting to load 2.0.0 from the root node_modules
, and exploding because it's not finding the expected commonjs export from 1.6.22:
$ yarn storybook
yarn run v1.22.17
$ start-storybook -p 6006
info @storybook/react v6.4.18
info
info => Loading presets
ERR! Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/me/test-case-mdx-import/node_modules/@mdx-js/mdx/index.js from /Users/me/test-case-mdx-import/node_modules/storybook-builder-vite/node_modules/vite-plugin-mdx/dist/imports.js not supported.
ERR! Instead change the require of index.js in /Users/me/test-case-mdx-import/node_modules/storybook-builder-vite/node_modules/vite-plugin-mdx/dist/imports.js to a dynamic import() which is available in all CommonJS modules.
ERR! at Object.requireMdx (/Users/me/test-case-mdx-import/node_modules/storybook-builder-vite/node_modules/vite-plugin-mdx/dist/imports.js:10:12)
ERR! at Object.createTransformer (/Users/me/test-case-mdx-import/node_modules/storybook-builder-vite/node_modules/vite-plugin-mdx/dist/transform.js:16:27)
ERR! at Object.configResolved (/Users/me/test-case-mdx-import/node_modules/storybook-builder-vite/node_modules/vite-plugin-mdx/dist/index.js:46:43)
ERR! at /Users/me/test-case-mdx-import/node_modules/vite/dist/node/chunks/dep-c9c9d3e5.js:70984:127
ERR! at Array.map (<anonymous>)
ERR! at resolveConfig (/Users/me/test-case-mdx-import/node_modules/vite/dist/node/chunks/dep-c9c9d3e5.js:70984:35)
ERR! at async createServer (/Users/me/test-case-mdx-import/node_modules/vite/dist/node/chunks/dep-c9c9d3e5.js:56354:20)
ERR! at async Object.start (/Users/me/test-case-mdx-import/node_modules/storybook-builder-vite/dist/index.js:43:20)
ERR! at async Promise.all (index 0)
ERR! at async storybookDevServer (/Users/me/test-case-mdx-import/node_modules/@storybook/core-server/dist/cjs/dev-server.js:126:28)
ERR! at async buildDevStandalone (/Users/me/test-case-mdx-import/node_modules/@storybook/core-server/dist/cjs/build-dev.js:115:31)
ERR! at async buildDev (/Users/me/test-case-mdx-import/node_modules/@storybook/core-server/dist/cjs/build-dev.js:161:5)
ERR! Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/me/test-case-mdx-import/node_modules/@mdx-js/mdx/index.js from /Users/me/test-case-mdx-import/node_modules/storybook-builder-vite/node_modules/vite-plugin-mdx/dist/imports.js not supported.
ERR! Instead change the require of index.js in /Users/me/test-case-mdx-import/node_modules/storybook-builder-vite/node_modules/vite-plugin-mdx/dist/imports.js to a dynamic import() which is available in all CommonJS modules.
ERR! at Object.requireMdx (/Users/me/test-case-mdx-import/node_modules/storybook-builder-vite/node_modules/vite-plugin-mdx/dist/imports.js:10:12)
ERR! at Object.createTransformer (/Users/me/test-case-mdx-import/node_modules/storybook-builder-vite/node_modules/vite-plugin-mdx/dist/transform.js:16:27)
ERR! at Object.configResolved (/Users/me/test-case-mdx-import/node_modules/storybook-builder-vite/node_modules/vite-plugin-mdx/dist/index.js:46:43)
ERR! at /Users/me/test-case-mdx-import/node_modules/vite/dist/node/chunks/dep-c9c9d3e5.js:70984:127
ERR! at Array.map (<anonymous>)
ERR! at resolveConfig (/Users/me/test-case-mdx-import/node_modules/vite/dist/node/chunks/dep-c9c9d3e5.js:70984:35)
ERR! at async createServer (/Users/me/test-case-mdx-import/node_modules/vite/dist/node/chunks/dep-c9c9d3e5.js:56354:20)
ERR! at async Object.start (/Users/me/test-case-mdx-import/node_modules/storybook-builder-vite/dist/index.js:43:20)
ERR! at async Promise.all (index 0)
ERR! at async storybookDevServer (/Users/me/test-case-mdx-import/node_modules/@storybook/core-server/dist/cjs/dev-server.js:126:28)
ERR! at async buildDevStandalone (/Users/me/test-case-mdx-import/node_modules/@storybook/core-server/dist/cjs/build-dev.js:115:31)
ERR! at async buildDev (/Users/me/test-case-mdx-import/node_modules/@storybook/core-server/dist/cjs/build-dev.js:161:5) {
ERR! code: 'ERR_REQUIRE_ESM'
ERR! }
If I yarn remove @mdx-js/mdx
(so the only one left in the project is the one you're depending on) everything works.
I don't know anything about Vite plugins or Storybook builders to know where to start on this one.
I know vite-plugin-mdx isn't this repo, but I could only reproduce the error when I coupled it with a storybook setup like this.
Cheers!