Not one LLM was able to help me fix this issue, so here I am. I'm building a Vite + React + TS project and it fails to build because of this error: [plugin:vite:css] [postcss] It looks like you're trying to use tailwindcss directly as a PostCSS plugin. The PostCSS plugin has moved to a separate package, so to continue using Tailwind CSS with PostCSS you'll need to install @tailwindcss/postcss and update your PostCSS configuration. The first one is a
I have tried:
require('tailwindcss') to require('@tailwindcss/postcss')My PostCSS file
plugins: {
'@tailwindcss/postcss': {},
autoprefixer: {},
},
}
My Vite file
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
tailwindcss(),
],
})
my index.css (snippet)
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
html {
Appreciate any help
Starting from v4, TailwindCSS provides separate plugins for PostCSS and Vite. You don't need to use both. For Vite, just use @tailwindcss/vite and you're good to go.
Additionally, the @tailwind directive has been deprecated since v4. Use
@import "tailwindcss";
instead.
Compared to v3, several breaking changes have been introduced. Here are some references to review these changes:
The installation of TailwindCSS v3 and v4 is different. You were expecting the v3 installation, but v4 is the new latest version. For v3 installation, use:
npm install -D tailwindcss@3
Once this is done, the other steps remain unchanged:
You seem to be using some v3 configs with some v4 configs at the same time.
Considering you want to use latest tailwindcss v4 with vite, you do not need to handle PostCSS manually.
Uninstall PostCSS, delete the PostCSS file and follow the steps here.
Your vite file seems to be correct.
Your index.css can lose the old v3 @tailwind directives in favour of the new @import "tailwindcss";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With