0

I tried to configure a new project using React, TypeScript and TailwindCSS v4 but Tailwind isn't applying.

Here is my installation:

npx create-react-app web
npm install --save-dev typescript @types/node @types/react @types/react-dom @types/jest
npx tsc --init
npm install --save-dev tailwindcss @tailwindcss/postcss postcss

I could use npx create-react-app web --template typescript but this way puts TypeScript in production dependencies. It is why I used my first steps.

Now, regarding Tailwind v4 doc I created postcss.config.mjs to the root, (near package.json) with this code:

export default {
  plugins: {
    "@tailwindcss/postcss": {},
  }
}

Then, in src/index.css, I removed all styles and I added only this line:

@import "tailwindcss";

Now I changed the App extension from App.js to App.tsx with this sample code:

function App() {
  return (
    <h1 className="text-3xl font-bold underline">
    Hello world!
  </h1>
  );
}

export default App;

and this is the 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();

Now I run npm start but Tailwind CSS not applied. Here is a screen:

result of npm start

Versions:

"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-scripts": "5.0.1",
"typescript": "^4.9.5",
"tailwindcss": "^4.0.12",
"postcss": "^8.5.3",

Did I miss a step?

7
  • 3
    Don't use create-react-app. It's outdated for at least 3 years. The two common ways are Vite and Next.js Commented Mar 11 at 9:53
  • 3
    Please don't use create-react-app. It is deprecated Commented Mar 11 at 10:03
  • 1
    Consider moving over to vite? Commented Mar 11 at 10:17
  • 1
    I tryed next, tailwind was working perfectly but i would like to configure i18n (react-i18next and i18next) i found a lot of webpack errors... Commented Mar 11 at 10:45
  • 2
    @Mafitsi that should be put in a different question btw Commented Mar 11 at 12:05

1 Answer 1

0

Short answer: Don't use create-react-app, as it is outdated. Alternatives: Next.js or Vite.

Deprecated Create React App

Deprecated

Create React App was one of the key tools for getting a React project up-and-running in 2017-2021, it is now in long-term stasis and we recommend that you migrate to one of React frameworks documented on Start a New React Project.

If you are following a tutorial to learn React, there is still value in continuing your tutorial, but we do not recommend starting production apps based on Create React App.


Source: facebook/create-react-app

Use Next.js instead of Create React App

Follow this: Creating a React App with Next.js App Router (react.dev) - React Docs

npx create-next-app@latest

After that follow TailwindCSS guide for Next.js:

npm install tailwindcss @tailwindcss/postcss postcss

Then you can easily integrate TailwindCSS to postcss.config.mjs using the @tailwindcss/postcss plugin released from v4 like this:

const config = {
  plugins: {
    "@tailwindcss/postcss": {},
  },
};
export default config;

And import TailwindCSS to main global.css:

@import "tailwindcss";

Alternative: Use Vite for React Project

Can use Vite with a simple installation step:

npm create vite@latest

Choose whether you need a React template, and whether you want a TypeScript or JavaScript-based starting point.

Then you can easily integrate TailwindCSS (even without postcss) using the @tailwindcss/vite plugin released from v4 like this:

npm install tailwindcss @tailwindcss/vite

Add the Vite plugin to vite.config.ts:

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

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

And import TailwindCSS to main app.css:

@import "tailwindcss";
Sign up to request clarification or add additional context in comments.

Comments

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.