Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Tailwind classes not rendering in react app

I am trying to include tailwind in my react typescript app. I followed the instructions here: https://tailwindcss.com/docs/guides/create-react-app

Basically I ran these commands in my existing app (which was created with create-react-app):

npm install -D tailwindcss postcss autoprefixer

npx tailwindcss init -p

And then I updated my tailwind.config.js.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My final loadout looks like this:

# tailwind.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ["./src/**/*.{js,jsx,ts,tsx}"],
  theme: {
    extend: {},
  },
  plugins: [],
};

#postcss.config.js

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

# package.json
{
  "name": "frf",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@mui/base": "^5.0.0-alpha.87",
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.3.0",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.5.2",
    "@types/node": "^16.11.41",
    "@types/react": "^18.0.14",
    "@types/react-dom": "^18.0.5",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "^2.1.3",
    "typescript": "^4.7.4",
    "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": "^10.4.7",
    "postcss": "^8.4.14",
    "tailwindcss": "^3.1.4"
  }
}
# src/index.css
@tailwind base;
@tailwind components;
@tailwind utilities;
# src/app.tsx
import React from "react";
import "./index.css";
import MainComponent from "./app/main/index";

function App() {
  return (
    <>
      <h1 className="underline">TEST</h1>
    </>
  );
}

export default App;

But my app loads without the underline styling under ‘TEST’ applied.

I assumed there is some sort of conflict with something in package.json, but I do not know what it is. I followed the same instructions on a fresh project without any other dependencies installed and it worked fine.

I have tried deleting node_modules and package-lock.json and running npm start again, but that did not work

>Solution :

Boss try this

npm i react-scripts@latest

source is here

tailwindcss not working in create-react-app

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading