Home > Blockchain >  Tailwind classes not rendering in react app
Tailwind classes not rendering in react app

Time:07-04

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.

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

CodePudding user response:

Boss try this

npm i react-scripts@latest

source is here

tailwindcss not working in create-react-app

  • Related