2

I want to use Tailwind CSS in my React app, but it is not working. I followed the description on the Tailwind site for how to install it, but the CSS is not being applied.

App.js

 // import './App.css'; import './index.css'; import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; import Home from './Home/Home' function App() { return ( <Router> <Routes> <Route> <Route exact path="/" element={<Home/>} /> </Route> </Routes> </Router> ); } export default App; 

index.css

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

tailwind.config

 module.exports = { content: [ "./src/**/*.{js,jsx,ts,tsx}", "./public/index.html", ], purge: [], darkMode: false, // or 'media' or 'class' theme: { extend: {}, }, variants: { extend: {}, }, plugins: [], } 

postcss.config.js

 module.exports = { plugins: { tailwindcss: {}, autoprefixer: {}, }, } 

package.json

 { "name": "archives", "version": "0.1.0", "private": true, "dependencies": { "@tailwindcss/postcss7-compat": "^2.2.17", "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.3.0", "@testing-library/user-event": "^13.5.0", "nanoid": "^4.0.0", "picocolors": "^1.0.0", "postcss-loader": "^7.0.1", "postcss-preset-env": "^7.7.2", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.3.0", "react-scripts": "^5.0.1", "source-map-js": "^1.0.2", "web-vitals": "^2.1.4" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }, "devDependencies": { "autoprefixer": "^9.8.8", "postcss": "^7.0.39", "postcss-flexbugs-fixes": "^5.0.2", "tailwindcss": "^3.1.6" } } 

Home.js

 import React from 'react'; import '../index.css'; const Home = () => { return ( <div className='w-full h-full'> <div className='flex justify-center'> <h1 className= 'text-2xl lg:text-5xl font-bold text-green-600 mt-12'> hi</h1> </div> </div> ); }; export default Home; 
5
  • 1
    yes i did i restart my app Commented Jul 18, 2022 at 16:54
  • 1
    "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.17" I don't think that's an usual version. Commented Jul 18, 2022 at 16:54
  • what i shold do ?? what the version shold i install!! Commented Jul 18, 2022 at 16:56
  • I suppose it should be something like "tailwindcss": "^3.1.0", and a second line with "@tailwindcss/postcss7-compat": "^2.2.17". My guess is that something when wrong when adding the packages. Commented Jul 18, 2022 at 16:58
  • i change it and uninstall the package and reinstall it it change to "tailwindcss": "^3.1.0" but it still not working Commented Jul 18, 2022 at 17:17

1 Answer 1

3

My tailwind is also broken, however, a few weeks ago I ran into the same issue.

The solution that worked for me was to add in any vanilla css to my index.css like so:

@tailwind base; @tailwind components; @tailwind utilities; body { background-color: #3f4040;` } 

(Sorry if this isn't a great post. It's my first!)

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.