I am just submitting this issue so that it can be searched by others.
Install these packages:
yarn add @emotion/babel-plugin @emotion/react
Modify your vite.config.ts
import { defineConfig } from "vite" ;
import react from "@vitejs/plugin-react" ;
// https://vitejs.dev/config/
export default defineConfig ( {
plugins : [
react ( {
jsxImportSource : "@emotion/react" ,
babel : {
plugins : [ "@emotion/babel-plugin" ] ,
} ,
} ) ,
] ,
} ) ;
Modify tsconfig.json
"compilerOptions" : {
"types" : [ "vite/client" , "@emotion/react/types/css-prop" ]
Modify .story/book/main.js
const react = require ( "@vitejs/plugin-react" ) ;
module . exports = {
stories : [ "../src/**/*.stories.mdx" , "../src/**/*.stories.@(js|jsx|ts|tsx)" ] ,
addons : [ "@storybook/addon-links" , "@storybook/addon-essentials" ] ,
framework : "@storybook/react" ,
core : {
builder : "storybook-builder-vite" ,
} ,
async viteFinal ( config ) {
config . plugins = config . plugins . filter (
( plugin ) =>
! ( Array . isArray ( plugin ) && plugin [ 0 ] ?. name . includes ( "vite:react" ) )
) ;
config . plugins . push (
react ( {
exclude : [ / \. s t o r i e s \. ( t | j ) s x ? $ / , / n o d e _ m o d u l e s / ] ,
jsxImportSource : "@emotion/react" ,
babel : {
plugins : [ "@emotion/babel-plugin" ] ,
} ,
} )
) ;
console . log ( config . plugins ) ;
return config ;
} ,
} ;
That's it! Happy coding!!
👍 React with 👍 25o-alexandrov, mu-hun, Kyun2da, guihigashi, oizys22 and 20 more 🎉 React with 🎉 6hatton, tsuki-lab, MickaelAustoni, mistical2008, ivankirshin and 1 more 🚀 React with 🚀 6yz4230, tsuki-lab, grlgmrs, MickaelAustoni, tuckwilli and 1 more