tailwindcss: tailwind 3 doesn't work with storybook/webpack setup
I’m using macOS, Chrome v96, Node.js 16
I created a github repository with this exact issue - https://github.com/sachinmour/tailwind-issue
Basically just do yarn and yarn storybook and you’ll see storybook loaded correctly.
change package.json to use tailwind ^3.0.0 and
run yarn and yarn storybook again and
you’ll see no tailwind is loaded inside storybook.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 25 (1 by maintainers)
Hi, the above staffs didn’t worked for me. here is the quick solution - in
.storybook/preview.jsfile add this line to compile tailwind generated css files like this -Here
tailwindcss/tailwind.cssis the tailwind css file. Look, important is I’ve to add!postcss-loader!to compile tailwind generated css.There are more solutions answered here - https://stackoverflow.com/a/70805809/5543577
@nvsd @LinnJS @paulgendek so, I figured out what the problem was, I don’t think it was because of what you guys said. The problem is in v3 of tailwindcss has JIT enabled by default and that means it’ll only add css that you use in your components, and in v2 if you didn’t define
modeand left the purge config as an empty array, it would add all of tailwindcss, but now you MUST define content property with all the places you’re using tailwindcss and as soon as I updated content to include my src folder, everything started working as usual. I’ve updated my original repo with working code https://github.com/sachinmour/tailwind-issueIf you guys don’t agree, let me know, otherwise, I’ll close this issue in 2 days.
We were able to get this working by NOT using
@storybook/addon-postcssand moving a copy ofpostcss.config.jsandtailwind.config.jsinto the.storybookdirectory..storybook/postcss.config.js:./storybook/tailwind.config.js:Everything else is the traditional setup (following the v3 upgrade guide).
@ManiruzzamanAkash answer almost fully worked for me. I also needed to add the line below for it to hot reload.
I documented the full setup below in case anyone else is struggling as this took me a day - includes setting up absolute paths. Question is how to setup Storybook with TailwindcssV3, ReactJS and Typescript: https://stackoverflow.com/questions/71329335/how-to-setup-storybook-with-tailwindcss-reactjs-and-typescript
I’m having a similar issue. I tried forcing Storybook to use PostCSS 8+ per the docs, but get the following error:
I have been working on a TailwindCSS component library for some time now. It took me forever to get Tailwind v2 working with Storybook nicely. I just upgraded to Tailwind V3 and had no issues like this.
My
main.jsfile looks like this:and my
preview.jsfile looks like:Not sure if this helps but I cant seem to reproduce your all’s error. I do have a similar error with my GatsbyJS project though 🙁 which is how I found this issue.
@jrock2004 For those who are still having this problem and is using postcss >= 8, I suggest you to do as following. Note: Credit to OP of these fixes. Thanks to them my project is working fine now.
Add this to
tailwind.config.jsAdd this to
preview.jsThis has helped me fix the problem and I hope it can help you too
@LinnJS @paulgendek if you can post a working repo or link, that’d be great.
I can confirm from @vatana7 that this did work for me just fine
I am still trying to figure this out. Seems like tailwind and storybook just are not friends right now
If anyone is still having issues with this, here is what I did step by step
Install storybook postcss addon
Add it into your
.storybook/main.jsfileimport tailwind into your
.storybook/preview.jsfilerestart storybook server and hopefully tailwind will work with storybook
@junaidrasheed You’ll likely get much quicker help posting this in discussions since this doesn’t relate to the issue.