2

I've been searching all over to try and resolve this issue. I created a React app with TypeScript and installed Tailwind CSS using the React setup shown on the Tailwind site here.

Below is my code and configuration. It runs successfully when I do a npm run start, but the Tailwind styles are not applied.

App.tsx

import React from 'react';
import logo from './logo.svg';
import './App.css';

function App() {
  return (
    <div className="items-center justify-center">
    <h1 className="text-3xl font-bold underline">
      Testing
    </h1>
    </div>
  );
}

export default App;

index.tsx

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement
);
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);
reportWebVitals();

index.css

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

postcss.config.js

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

tailwind.config.js

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

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

package.json

{
  "name": "mortgage-calc",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@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.43",
    "@types/react": "^18.0.15",
    "@types/react-dom": "^18.0.6",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "^5.0.1",
    "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.5"
  }
}

My output My output

7
  • did you quit the server after installing tailwind? if not then then please restart it, maybe it will start working, I had the same problem Commented Jul 11, 2022 at 20:21
  • Yep, I've restarted it a few times just in case and I get the same thing. I've updated my post to show what I see when I do a npm run start. Commented Jul 11, 2022 at 20:26
  • try to change your tailwind config.js. to this, module.exports = { content: [ "./src/**/*.{js,jsx,ts,tsx}", ], theme: { extend: {}, }, plugins: [], } Commented Jul 11, 2022 at 20:31
  • Exactly what is mentioned on the official site you took reference from Commented Jul 11, 2022 at 20:32
  • Has no effect whatsoever, and adding the component portion is just scanning my components folder for styles as well. Commented Jul 11, 2022 at 20:42

1 Answer 1

1

Try to remove the spaces between the file endings in your tailwind.config.js:

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

If that doesn't correct your problem, try to remove the CSS import in your App.tsx:

import React from 'react';
import logo from './logo.svg';

function App() {
  return (
    <div className="items-center justify-center">
    <h1 className="text-3xl font-bold underline">
      Testing
    </h1>
    </div>
  );
}

export default App;
Sign up to request clarification or add additional context in comments.

1 Comment

You're awesome! Nice catch, it was the spaces in the tailwind.config.js content.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.