This article describes the issue "Tailwind CSS was not compiled correctly" that I encountered while creating my tech blog site.
I created a Next.js app with the following tech stack, consulting with GPT-4:
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/app/**/*.{js,ts,jsx,tsx}",
"./src/components/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
};
@tailwind base;
@tailwind components;
@tailwind utilities;
import "./globals.css";
export const metadata = {
title: "Your App Title",
description: "Your App Description",
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
When using the Tailwind style "mb-20" in the child page (app/page.tsx), the following statement was not included in the compiled file (.next/static/css/app/page.css):
.mb-20 {
margin-bottom: calc(var(--spacing) * 20);
}
The issue was caused by incorrect configuration. For Tailwind CSS v4.0.0 and above, it should be installed as a plugin using Vite or postcss. reference : https://tailwindcss.com/docs/installation/using-postcss In my case, I resolved the issue by following these steps:
postcss.config.js
.postcss.config.js
.
(tailwind.config.js seems not neccesaary.)export default {
plugins: {
"@tailwindcss/postcss": {},
},
};