How to make styled-components work with Vite during production build? #4098
-
I recently moved from create-react-app to Vite. Everything is working perfectly in dev server but when I build for production with vite my styles are all messed up it seems they aren't applied properly. So, is there any extra config needed to make styled-component work. In CRA I used babel and |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 8 replies
-
I solved it. It wasn't a issue with Vite. Somehow doing a CSS @import inside styled component caused that and removing it solved it. I also had issue while deploying to netlify which mentioned |
Beta Was this translation helpful? Give feedback.
-
@silenceofthewans That means currently styled components is supported by Vite, right? |
Beta Was this translation helpful? Give feedback.
-
@silenceofthewans I'm also trying to use React + Styled Components with Vite. I would like to have full class names of the styled components on development, which was done with Any help appreciated, thanks! |
Beta Was this translation helpful? Give feedback.
-
I made it work with |
Beta Was this translation helpful? Give feedback.
-
Thanks! I wrote a simple |
Beta Was this translation helpful? Give feedback.
-
Hi, right now when you installs styled components, automatically at json package it's add "babel-plugin-styled-components" |
Beta Was this translation helpful? Give feedback.
I solved it. It wasn't a issue with Vite. Somehow doing a CSS @import inside styled component caused that and removing it solved it. I also had issue while deploying to netlify which mentioned
[vite]: Rollup failed to resolve import "react-is" from "node_modules/styled-components/dist/styled-components.browser.esm.js".
and I fixed that one by setting node & npm versions in netlify to latest.