Tailwind CSS v4 with React + Vite: Styles not applied on first load in dev mode #16399
Replies: 2 comments 15 replies
-
Make sure you have followed the tailwind CSS official setup guide. There seems to be no problem with the code you have provided. Can you share the vite.config.js file? |
Beta Was this translation helpful? Give feedback.
-
First of all, in your vite.config file, in the plugins array remove the tailwindcss() because tailwind v4 integrates automatically when the tailwindcss package is installed. So your vite.config file should be: ` export default defineConfig({ If none of this works, you can try deleting your node_modules folder and then running I have never experienced this issue before so I apologize for wasting your time. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am experiencing an issue with Tailwind CSS v4 in a Vite project where styles are not applied on the first page load when running pnpm dev. However, after a manual refresh (F5), Tailwind styles are applied correctly. This issue does not occur in production builds (pnpm build && pnpm preview), where styles are immediately available.
This behavior suggests that Tailwind’s auto-content discovery or Vite’s HMR may not be correctly detecting the styles on the initial dev build.
Steps to Reproduce
1. Initialize a Vite + React project using Tailwind CSS v4.
2. Install dependencies:
Expected Behavior
Tailwind styles should be applied immediately on the first page load in dev mode, without requiring a manual refresh.
Actual Behavior
• On the initial page load, Tailwind styles are missing.
• After manually refreshing the page, the styles appear correctly.
• Production build works without issues.
Development Environment
Beta Was this translation helpful? Give feedback.
All reactions