1

I setup a React project with Vite. I also installed TailwindCSS successfully with no errors in the terminal. I followed all documentation instructions but on trying to use the Tailwind classes from the doc examples, none are working. My final rendered HTML don't reflect the styles I have set on them.

vite.config.js

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from "tailwindcss"

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  css: {
    postcss: {
      plugins: [tailwindcss()],
    }
  }
})

tailwind.config.js

/** @type {import('tailwindcss').Config} */
export default {
  content: [
    "./index.html",
    "./src/**/*.{js, ts, jsx, tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

index.css

@itailwind components;
@tailwind utilities;
@tailwind base;

postcss.config.js

export default {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}

Here's a repo containing the full project files: Tailwind Test

1

1 Answer 1

1

Finally figured out that the problem came from the tailwind.config.js file. In the content array, js came before jsx which was blocking what it was supposed to do.

One thing I don't understand is that I thought since they were listed, Tailwind is supposed to pick the one applicable to it (that is, the jsx). Why did I have to clear the js in front before it worked?

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

1 Comment

Maybe it was the spaces in your extension names? All of the examples I've seen had no spaces. I'm assuming by removing js, you put jsx in front with no spaces.

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.