Tailwind CSS v4 + Vite + React: npx tailwindcss init fails & styles not applied #19466
mustafa3mahmoud
started this conversation in
General
Replies: 1 comment
-
|
thanks for sharing this. you figured it out correctly - tailwind v4 removed the CLI and uses vite plugin instead. just want to add for others who find this: if youre using postcss (not vite plugin), the setup is different: npm install tailwindcss @tailwindcss/postcsspostcss.config.js: export default {
plugins: {
"@tailwindcss/postcss": {}
}
}the vite plugin approach you showed is better for vite projects though - faster builds and better HMR. also the import changed from: // v3
@tailwind base;
@tailwind components;
@tailwind utilities;to: // v4
@import "tailwindcss";good catch on documenting this |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Tailwind CSS v4 in a Vite
I ran into a confusing issue while setting up Tailwind CSS v4 in a Vite + React project on Windows.
Environment :
Problem Description :
While setting up Tailwind CSS v4 in a Vite + React project :
npm install -D tailwindcss postcss autoprefixernpx tailwindcss init -pnpm error could not determine executable to runNo
tailwind.config.jsorpostcss.config.jsis created.Importing Tailwind in CSS (
@import "tailwindcss";) did not apply any styles.Silent failure, no runtime errors in browser.
Attempts that did NOT fix the problem :
Root cause :
Tailwind CSS v4 no longer provides a CLI like v3,
and when using Vite + React, Tailwind v4 requires the Vite plugin.
Without the plugin, Tailwind fails silently.
Solution :
1) Install the Vite plugin :
npm install -D @tailwindcss/vite2) Add it to
vite.config.js:3) Import Tailwind in your main CSS file :
@import "tailwindcss";4) Restart the dev server :
npm run devAfter adding the plugin, Tailwind works immediately.
Recommendation :
Consider updating the documentation to clearly note that Tailwind CSS v4 requires the
@tailwindcss/vite pluginfor Vite projects. Without it, Tailwind may not work correctly in some setups, leading to silent failures or missing styles. Many users (including myself) have encountered this issue when setting up Tailwind v4 with Vite + React.Beta Was this translation helpful? Give feedback.
All reactions