When I try to run my react project, I get this error:
npm run dev
> [email protected] dev
> vite
failed to load config from E:\hp\Task\React-challenge\vite.config.js
error when starting dev server:
Error: It looks like you're trying to use `tailwindcss` directly as a PostCSS plugin. The PostCSS plugin has moved to a separate package, so to continue using Tailwind CSS with PostCSS you'll need to install `@tailwindcss/postcss` and update your PostCSS configuration.
at zr (file:///E:/hp/Task/React-challenge/node_modules/tailwindcss/dist/lib.mjs:22:1720)
at file:///E:/hp/Task/React-challenge/node_modules/.vite-temp/vite.config.js.timestamp-1740937809009-d3caf28be0035.mjs:10:17
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
I reinstalled my tailwindcss and postcss again, however I get the same error.
This my vite.config.js:
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "tailwindcss";
import autoprefixer from "autoprefixer";
export default defineConfig({
plugins: [react()],
css: {
postcss: {
plugins: [tailwindcss(), autoprefixer()],
},
},
});
This is my tailwind.config.js:
// tailwind.config.js
module.exports = {
darkMode: 'class', // Enable class-based dark mode
content: [
'./index.html',
'./src/**/*.{js,ts,jsx,tsx}',
],
theme: {
extend: {},
},
plugins: [],
};
This is my post.config.js:
// postcss.config.js (ES Module syntax)
import tailwindcss from 'tailwindcss';
import autoprefixer from 'autoprefixer';
export default {
plugins: [
tailwindcss,
autoprefixer,
],
};