builder-vite: @mdx-js_react.js does not provide an export named 'mdx' [Bug]
What version of vite are you using?
2.9.9
System info and storybook versions
Environment Info:
System: OS: macOS High Sierra 10.13.6 CPU: (8) x64 Intel® Core™ i7-4870HQ CPU @ 2.50GHz Binaries: Node: 16.14.2 - /usr/local/bin/node Yarn: 3.2.0 - /usr/local/bin/yarn npm: 8.6.0 - /usr/local/bin/npm Browsers: Chrome: 101.0.4951.64 Edge: 101.0.1210.53 Firefox: 97.0.1 Safari: 13.1.2 NPM Packages
“dependencies”: { “vue”: “^3.2.25” }, “devDependencies”: { “@babel/core”: “^7.18.2”, “@mdx-js/react”: “^2.1.1”, “@storybook/addon-actions”: “^6.5.6”, “@storybook/addon-essentials”: “^6.5.6”, “@storybook/addon-interactions”: “^6.5.6”, “@storybook/addon-links”: “^6.5.6”, “@storybook/addon-postcss”: “^2.0.0”, “@storybook/builder-vite”: “^0.1.35”, “@storybook/testing-library”: “^0.0.11”, “@storybook/vue3”: “^6.5.6”, “@tailwindcss/forms”: “^0.5.2”, “@vitejs/plugin-vue”: “^2.3.3”, “autoprefixer”: “^10.4.7”, “babel-loader”: “^8.2.5”, “postcss”: “^8.4.14”, “tailwindcss”: “^3.0.24”, “vite”: “^2.9.9”, “vue-loader”: “^16.8.3” }
Describe the Bug
MDX files throw the following error in Storybook:
SyntaxError: The requested module '/node_modules/.vite-storybook/deps/@mdx-js_react.js?v=4345b16f' does not provide an export named 'mdx'
I am using Storybook inside an NPM workspace / Monorepo. If I install Storybook into a fresh project (outside the monorepo) I do not have this issue.
Any ideas?
Link to Minimal Reproducible Example
No response
Participation
- I am willing to submit a pull request for this issue.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 18 (7 by maintainers)
Interesting. I think you can work around this for now with
npm i --save-dev @mdx-js/react@1 --force.Sorry to reopen this issue but I’m getting this error and I’m using react v17 in my pnpm monorepo… I can’t get mdx to work with storybook…
Hi @IanVS - Thanks for addressing this! Other than as a dependency of Storybook(?) I’m not using React anywhere. Everything I build is in Vue3.
Well, that got rid of the error message! But now when I load
Introduction.stories.mdxI just get a blank page.When I check the console, I see these errors:
It looks like you’ve got a mix of react 18 and react 17 in the project, due to different sub-packages wanting different versions. I think that perhaps, if you delete your
package-lock.json, remove your node_modules, and re-install, you might be back in a working state. If that fails, you can always try runningnpm i --legacy-peer-deps.Hopefully this is a temporary condition until we can get mdx straightened out.
I’m also on React 18 w/vite, and I was able to get up and running with
npm i --save-dev @mdx-js/react@1 --force(actuallypnpm, in my case).@IanVS my hero! I’m in the middle of upgrading a React/Storybook/Vite project to React 18, ran into this exact issue where mdx stories wouldn’t load due to the error and your suggestion to install 1.x of mdx-js/react worked! Also this quote
So glad I found this GH issue, because I was confused why I was still seeing that message in the console and thought the upgrade didn’t work 😇
Wow, that did it! Thanks @IanVS - that’s fantastic!
@adamSneller sorry, that suggestion was for @l4dybird. I took a look at your reproduction (thanks for providing it), and I got it working by explicitly installing react@17. This shouldn’t have to be necessary, and hopefully you’ll be able to remove it once we get MDX all sorted out. I pushed up two commits to the main branch of your repo.