Open zettadam opened 2 years ago
Exact same problem here.
I found a dirty workaround, replacing react({ jsxRuntime: 'classic' })
(from vite.config.ts
) with react()
:
// main.ts
import { StorybookConfig } from '@storybook/react-vite';
import react from '@vitejs/plugin-react';
const config: StorybookConfig = {
core: {
builder: '@storybook/builder-vite',
},
framework: {
name: '@storybook/react-vite',
},
// ... other stuff
viteFinal: (config) => ({
...config,
plugins: config.plugins?.map((plugin) => {
if (plugin?.[0]?.name === 'vite:react-babel') return react();
return plugin;
}),
}),
};
export default config;
But yeah, I'm also interested in non-hacky way to separately configure the JSX Runtime for Storybook.
I'm getting this same error on Storybook React Native without Vite.
@spsaucier Perhaps file an issue on the RN repo? https://github.com/storybookjs/react-native
For anybody who's experiencing this, is it still a problem on 7.0?
Migration guide: https://storybook.js.org/migration-guides/7.0
Describe the bug
I want to create a library of React components and document them with Storybook. Since I use
vite
in library mode to build components I thought of using Storybook withvite
builder. Storybook v7-alpha is using the samevite
configuration, but in library mode I want to build my components with "classic" JSX runtime configured with@vitejs/plugin-react
to avoid shipping JSX runtime with my component library--it's up to library consumers to configure it on their side.Below is my
vite.config.ts
However, this setting breaks Storybook and this is where having zero configuration approach is not working as expected or documented with
async viteFinal ()
override in./storybook/main.js
(I use Typescript & .tsx files with library source files, but JS & .{jsx|mdx} files with stories).Below is my
./storybook/main.js
configuration:I receive errors related to duplicate React/JSX runtime environments, deprecated Babel
transform-react-jsx-self
plugin, like:I recently filed a bug report related to "classic" JSX runtime in library mode with Vite project and it got fixed on their side. I was thinking that with
async viteFinal()
function I could override library@vitejs/plugin-react
configuration, but I run into these issues.Is there a documented and tested way of specifying different JSX runtime configuration for libraries and storybook re-/using the same
vite.config.{js|ts}
configuration?To Reproduce
System
Additional context
My package.json: