Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Vite reports that tailwindcss cannot be used directly as a PostCSS plugin

ErrorInternal server error: [postcss] It looks like you're trying to use `tailwindcss` directly as a PostCSS plugin.

Short answer

In Tailwind CSS v4 the PostCSS plugin moved out of the tailwindcss package. A v3-style postcss.config that lists tailwindcss now fails. In a Vite project, delete that config entry, install @tailwindcss/vite, add it to vite.config, and import Tailwind with a plain CSS @import line.

  • Applies to Tailwind CSS 4, Vite 8, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check which Tailwind version is installed, then look at your PostCSS config.

    npm ls tailwindcss
    cat postcss.config.* 2>/dev/null
  2. 2Match what you see, then jump to its fix

    1. 1postcss.config lists tailwindcss while npm ls shows version 4A v3 postcss.config still names tailwindcssFix
    2. 2Other PostCSS plugins must stay in the pipelineYou want to keep PostCSSFix
    3. 3The PostCSS error is gone, but no Tailwind styles appearThe stylesheet still uses the v3 directivesFix

What does the error look like?

  • Internal server error: [postcss] It looks like you're trying to use `tailwindcss` directly as a PostCSS plugin.

Cause 1 of 3

A v3 postcss.config still names tailwindcss

1Check

The upgrade guide says the v3 package was the PostCSS plugin, and in v4 it lives in a dedicated package.

grep -n "tailwindcss" postcss.config.*

2Fix

For Vite, the recommended route is the Vite plugin. Install it, register it, and remove the Tailwind entry from the PostCSS config (delete the file if nothing else is in it).

npm install tailwindcss @tailwindcss/vite

// vite.config.ts
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'

export default defineConfig({
  plugins: [tailwindcss()],
})

3Verify

Restart the dev server. The error should be gone.

npm run dev

Confirmed by tailwindcss.com

Did this fix it?

Cause 2 of 3

You want to keep PostCSS

1Check

If you choose PostCSS, the plugin name changes to @tailwindcss/postcss. v4 also handles imports and vendor prefixes itself, so postcss-import and autoprefixer can be removed.

npm ls @tailwindcss/postcss

2Fix

Install the new package and list it in place of tailwindcss.

npm install @tailwindcss/postcss

// postcss.config.mjs
export default {
  plugins: {
    "@tailwindcss/postcss": {},
  },
};

3Verify

Restart the dev server.

npm run dev

Confirmed by tailwindcss.com

Did this fix it?

Cause 3 of 3

The stylesheet still uses the v3 directives

1Check

v3 used three @tailwind lines. v4 uses one CSS import.

grep -rn "@tailwind\|@import \"tailwindcss\"" src/

2Fix

Replace the old lines with the import.

/* src/index.css */
@import "tailwindcss";

3Verify

Add a utility class such as text-3xl to an element and reload.

npm run dev

Confirmed by tailwindcss.com

Did this fix it?

How do I stop it coming back?

  • After the upgrade, keep only one Tailwind entry point: the Vite plugin or the PostCSS plugin, not both.
  • Read the upgrade guide before you move a project from Tailwind v3 to v4.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.