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
[Bug]: Failed to resolve module specifier "react" (@storybook/react-vite) #22630
Comments
I'm having a similar issue.
|
This seems to occur after 7.0.7. I have one using that and it seems to be fine. The other one using 7.0.12 has this problem. |
Do you a have a reproduction repo you can share? If not, can you create one? Go to https://storybook.new or see repro docs. Thank you! 🙏 |
Actually I do have a repro. https://github.com/justland/just-web-react pnpm i
pnpm react sb:build The folder will be in You can run the |
This is the result of the Vite builder being a bit too smart, and we have to workaround that. That's because Storybook automatically extends the user's In your case that makes sense, because you're building a library, and you don't want to include The workaround is to remove the externals plugin with import type { StorybookConfig } from '@storybook/react-vite'
+ import { withoutVitePlugins } from '@storybook/builder-vite'
const config: StorybookConfig = {
stories: ['../ts/**/*.stories.mdx', '../ts/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'@storybook/addon-storysource',
'storybook-dark-mode',
{
name: '@storybook/addon-styling',
options: {
postCss: true
}
}
],
framework: {
name: '@storybook/react-vite',
options: {}
},
features: {
storyStoreV7: true
},
typescript: {
check: false
},
docs: {
autodocs: true
},
+ viteFinal: async config => {
+ return { ...config, plugins: await withoutVitePlugins(config.plugins, ['node-externals']) }
+ }
}
export default config you also need to add (If you test this out by serving your build output, make sure to reload the browser with DevTools open and caching disabled. The browser will aggressively cache the site, showing the error even if it has been fixed) This is not the first time we run into this for library authors, and we want to improve the documentation and experience around this issue. |
Thanks. Will try that. But if that is the cause, why Does that uses the cite config differently? |
That's because Vite only uses Rollup for production builds, and esbuild in development. And the plugin is a rollup-only plugin. |
Would like to share that the library mode for vite is quite limited. It's more flexible and not impacted by this issue. :) |
@kylegach ultimately I think this is something we need to document, a quirk when using Vite and building a library, not an application. I'll be happy to explain it in greater detail if my previous comment isn't enough. |
I'm sadly having this issue still , after adding the vitefinal fix |
I replaced the build with swc and worked fine
|
"storybook": "^8.0.4" same issue with Vite in lib mode (react as peerDependency) |
YEAH! Found solution, thanks @JReinhold!
viteFinal: async (config) => {
+ console.log('config', config.plugins);
return {
...config,
plugins: await withoutVitePlugins(config.plugins, ['peer-deps-external']),
};
},
viteFinal: async (config) => {
return {
...config,
+ plugins: await withoutVitePlugins(config.plugins, ['peer-deps-external']),
};
}, |
Describe the bug
When running
storybook dev
, it is working fine.But if it is built by running
storybook build
, and load the resultingindex.html
,It fails with:
Failed to resolve module specifier "react". Relative references must start with either "/", "./", or "../".
To Reproduce
Do not have a repro yet
System
Additional context
I have also seen
Failed to resolve module specifier "uuid"
, orFailed to resolve module specifier "some-library"
, wheresome-library
is used inpreview.tsx
.The text was updated successfully, but these errors were encountered: