DEV Community

Cover image for ๐Ÿš€ Fixing Tailwind Init Error in React (Vite) Projects
Khushalsarode
Khushalsarode

Posted on

๐Ÿš€ Fixing Tailwind Init Error in React (Vite) Projects

Integrating Tailwind CSS with a React + Vite project is usually smooth โ€” but if youโ€™ve run into an error during the tailwindcss init process, donโ€™t worry. This guide walks you through the right way to set up Tailwind, what causes the init error, and how to fix it quickly.

โœ… Step 1: Create a React + Vite Project

First, set up your React app using Vite:

npm create vite@latest <project_name> --template react
Enter fullscreen mode Exit fullscreen mode

Prompts to follow:

  • Project name: project_name
  • Framework: React
  • Variant: JavaScript

Then, navigate into your project and install dependencies:

cd tech-stack-suggestor
npm install
Enter fullscreen mode Exit fullscreen mode

โœ… Step 2: Install Tailwind CSS

Hereโ€™s where many developers hit the error. The standard command is:

npm install -D tailwindcss postcss autoprefixer
Enter fullscreen mode Exit fullscreen mode

Installed Tailwind postcss autoprefixer

However, you may see an error during tailwindcss init, especially if the Tailwind CLI version is mismatched or if PostCSS isnโ€™t configured properly.

โŒ The Problem: Tailwind Init Error

In some cases, running:

npx tailwindcss init -p
Enter fullscreen mode Exit fullscreen mode

Results in an error like:
Fails silently without generating the tailwind.config.js and postcss.config.js files.

Error while Init the tailwind config files

Error:

npm ERR! could not determine executable to run
npm ERR! A complete log of this run can be found in: C:\Users\HP.KHUSHALSARODE.000\AppData\Local\npm-cache\_logs\2025-05-26T16_52_47_671Z-debug-0.log

Enter fullscreen mode Exit fullscreen mode

๐Ÿ’ก Cause:

The init command is no longer available in Tailwind CSS v4. For v3, 
make sure to use the correct version qualifier during installation.
Enter fullscreen mode Exit fullscreen mode

โœ… The Fix: Specify Tailwind Version Explicitly

npm install -D [email protected] postcss autoprefixer
npx tailwindcss init -p
Enter fullscreen mode Exit fullscreen mode

This will correctly generate the tailwind.config.js and postcss.config.js files, resolving the init error.

Config files generated successfully

โœ… Step 3: Configure Tailwind

Update tailwind.config.js like this:

/** @type {import('tailwindcss').Config} */
export default {
  content: [
    "./index.html",
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

Enter fullscreen mode Exit fullscreen mode

Then, update ./src/index.css:

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

Enter fullscreen mode Exit fullscreen mode

Make sure this CSS file is imported in your main.jsx or main.tsx:

import './index.css';

Enter fullscreen mode Exit fullscreen mode

โœ… Step 4: Run Your App

Now start the development server:

npm run dev
Enter fullscreen mode Exit fullscreen mode

Your Tailwind-powered React app should be live at:

http://localhost:5173

Enter fullscreen mode Exit fullscreen mode

Top comments (0)