0

I'm having a persistent issue integrating Tailwind CSS v4 into a Vite/React project, and I'm hoping someone here might have some insight.

Problem:

Tailwind utility classes are not being generated in my local build. The output CSS file includes the @theme layer with all the design tokens and the @layer base with the CSS reset, but the @layer utilities block is completely empty, containing only @tailwind utilities;. This means none of the classes I use in my components are working.

Setup:

Tailwind CSS v4 ([email protected]) Vite ([email protected]) React ([email protected], @vitejs/[email protected]) Using the first-party Vite plugin (@tailwindcss/[email protected]) Importing my main CSS file (src/index.css) into my main JSX entry file (src/index.jsx). index.css contains only @import "tailwindcss";. Key Observations:

If I use the Tailwind CDN in my index.html, all styles work correctly. This confirms my HTML structure and class names are fine. If I remove the @import "tailwindcss"; from index.css, other non-Tailwind CSS rules I might add work (though obviously Tailwind utilities don't). This suggests the issue is tied to the @import processing step.

Request for Help:

Despite these steps, Tailwind is still not scanning my content files and generating utilities locally. It seems like the @tailwindcss/vite plugin isn't correctly triggering or performing the content scanning step.

Has anyone encountered a similar issue with Tailwind v4 and the Vite plugin where utilities aren't generated even with explicit content configuration? Are there any known compatibility issues with the versions I'm using, or other potential causes related to how the plugin interacts with Vite or the file system in this scenario?

Any suggestions or guidance on how to further debug this would be greatly appreciated!

My vite.config.js:

import react from '@vitejs/plugin-react';
import tailwindcss from '@tailwindcss/vite'

export default defineConfig({
  base: '/aphians',
  plugins: [
    tailwindcss(),
    react()
  ],
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    sourcemap: false
  }
});

My index.css:

@import "tailwindcss";

And package.json

    {
  "name": "client",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "start": "vite --host",
    "start:debug": "vite --debug --logLevel info",
    "build": "vite build --base=/aphians"
  },
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^7.5.3"
  },
  "devDependencies": {
    "@tailwindcss/vite": "^4.1.7",
    "@vitejs/plugin-react": "^4.0.0",
    "tailwindcss": "^4.1.6",
    "vite": "^5.0.0"
  }
}

Troubleshooting Steps Taken:

Confirmed @tailwindcss/vite plugin was installed (it was initially missing, but issue persists after installing). Performed multiple clean installations (deleted node_modules, package-lock.json, and reinstalled). Ensured index.css contains only @import "tailwindcss";. Ensured vite.config.js correctly imports and uses the tailwindcss() plugin. Explicitly defined the content array within the tailwindcss({}) plugin options in vite.config.js (./index.html, ./src/**/*.{js,jsx,ts,tsx}). Simplified the content array to target a single known file (./src/components/LandingPage.jsx) containing Tailwind classes. Removed the content option from the Vite plugin and created a minimal tailwind.config.js file in the project root with only the content array defined. Verified Vite can resolve the paths to my component files (seen in debug logs). Using Node.js version: v20.19.1

5
  • 1
    If I remove the @import "tailwindcss"; from index.css, other non-Tailwind CSS rules I might add work (though obviously Tailwind utilities don't). - There's no other custom CSS in the shared index.css. What do you mean exactly? Using custom CSS can strongly affect how things work if Tailwind is imported incorrectly or improperly, which is why a minimal reproduction would be necessary. If index.css is your main CSS file, then @import "tailwindcss"; is the very first line in it, right? Commented May 16 at 7:38
  • ` Removed the content option from the Vite plugin and created a minimal tailwind.config.js file in the project root with only the content array defined.` - I don't understand this. Tailwind CSS v4 no longer uses tailwind.config.js, so its contents are completely irrelevant - we're not using it. It can be deleted. The content property that was declared in v3 has been removed in v4 and replaced by automatic source detection. See more: What's breaking changes from v4? Commented May 16 at 7:41
  • Off: Without formatting, your question is quite hard to follow. It's too long, but I tried to highlight the parts that stood out to me. Commented May 16 at 7:42
  • Please, share a very minimal reproduction with only the essential dependencies and a sample React component on e.g. StackBlitz. Commented May 16 at 7:43

1 Answer 1

3

Thanks to @rozsazoltan for your pointers. I was able to solve my problem. Turns out my vite installation was corrupt and incomplete. I setup a new project and moved all my existing codebase in the new project and it is all good now.

Sign up to request clarification or add additional context in comments.

1 Comment

I also Facing the same issue how to solve that one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.