builder-vite: [Bug] Missing package @mdx-js/react on scratch build sveltekit + storybook + builder-vite
What version of vite are you using?
2.9.9
System info and storybook versions
System: OS: macOS 12.3.1 CPU: (10) arm64 Apple M1 Pro Binaries: Node: 18.0.0 - /opt/homebrew/bin/node npm: 8.9.0 - /opt/homebrew/bin/npm Browsers: Chrome: 101.0.4951.64 Firefox: 100.0 Safari: 15.4 npmPackages: @storybook/addon-actions: ^6.5.3 => 6.5.3 @storybook/addon-essentials: ^6.5.3 => 6.5.3 @storybook/addon-interactions: ^6.5.3 => 6.5.3 @storybook/addon-links: ^6.5.3 => 6.5.3 @storybook/builder-vite: ^0.1.35 => 0.1.35 @storybook/builder-webpack4: ^6.5.3 => 6.5.3 @storybook/manager-webpack4: ^6.5.3 => 6.5.3 @storybook/svelte: ^6.5.3 => 6.5.3 @storybook/testing-library: ^0.0.11 => 0.0.11
Describe the Bug
Created a scratch project with Sveltekit(1.0.0-next.335), storybook (6.5.3) and builder-vite. This project with webpack works fine.
But when starting storybook, I’m presented with the following error:
info => Ignoring cached manager due to change in manager config
ERR! Error: [vite-plugin-mdx] "@mdx-js/react" must be installed
ERR! at resolveImport (/Users/maximehuylebroeck/Documents/Development/storybook-load-API-data-via-loaders/node_modules/vite-plugin-mdx/dist/imports.js:29:23)
ERR! at Object.assertImportExists (/Users/maximehuylebroeck/Documents/Development/storybook-load-API-data-via-loaders/node_modules/vite-plugin-mdx/dist/imports.js:41:12)
ERR! at /Users/maximehuylebroeck/Documents/Development/storybook-load-API-data-via-loaders/node_modules/vite-plugin-mdx/dist/transform.js:18:19
ERR! at Array.map (<anonymous>)
ERR! at Object.createTransformer (/Users/maximehuylebroeck/Documents/Development/storybook-load-API-data-via-loaders/node_modules/vite-plugin-mdx/dist/transform.js:17:50)
ERR! at Object.configResolved (/Users/maximehuylebroeck/Documents/Development/storybook-load-API-data-via-loaders/node_modules/vite-plugin-mdx/dist/index.js:46:43)
ERR! at /Users/maximehuylebroeck/Documents/Development/storybook-load-API-data-via-loaders/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:61561:127
ERR! at Array.map (<anonymous>)
ERR! at resolveConfig (/Users/maximehuylebroeck/Documents/Development/storybook-load-API-data-via-loaders/node_modules/vite/dist/node/chunks/dep-59dc6e00.js:61561:35)
ERR! at async getOptimizeDeps (/Users/maximehuylebroeck/Documents/Development/storybook-load-API-data-via-loaders/node_modules/@storybook/builder-vite/dist/optimizeDeps.js:127:28)
Link to Minimal Reproducible Example
https://github.com/GeForcez/storybook-load-API-data-via-loaders
Participation
- I am willing to submit a pull request for this issue.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (8 by maintainers)
WOW! I SOLVED!
It seems like this only happens when you are on React 18?
I think we’re perhaps moving away from using
vite-plugin-mdx(see https://github.com/storybookjs/builder-vite/pull/377), but for now, a workaround is to manually install the package that it can’t find:After that, (plus setting the builder and adding a
preview-head.html) I was able to launch the reproduction correctly.@IanVS Yes, understand completely. I hope it didn’t come too strong. I was simply looking at it from the point of view of someone who might take Storybook for a spin in a project built with Vite.
I just sent a starter project with what seemed to me as straightforward dependencies to a friend so he could test Storybook with pure HTML. It worked on my machine when I initiated it with
npx sb init...command. When I removed ‘node_modules’ and ‘package-lock.json’, and runnpm install&npm run storybookI saw missing dependencies and then other errors in the browser after I thought I had manually fixed dependencies.I imagine my friend to be totally frustrated.
My package.json
Hi @IanVS
After installing the dependency
@mdx-js/react@1I get another error:Any idea how to fix this? Thank you! 😃