Skip to content

Fixing PostCSS Plugin tailwindcss Requires PostCSS 8 Error

Problem Overview

When migrating to Tailwind CSS v2 or later versions, developers often encounter the error: "PostCSS plugin tailwindcss requires PostCSS 8." This occurs because Tailwind CSS v2+ requires PostCSS 8, but your project is using an older version of PostCSS or related tooling.

The error typically appears in build processes with stack traces indicating compatibility issues between Tailwind CSS and PostCSS versions.

VERSION COMPATIBILITY

Tailwind CSS v2.0+ requires PostCSS 8. If you're using tools that haven't updated to PostCSS 8 (such as older versions of Vue CLI, Webpack, or other build tools), you'll encounter this compatibility error.

Solutions

For new projects or when you can update your build tooling:

bash
npm uninstall tailwindcss postcss autoprefixer
npm install -D tailwindcss@latest postcss@latest autoprefixer@latest
Package.json changes

Ensure your package.json includes these versions or higher:

json
{
  "devDependencies": {
    "tailwindcss": "^3.0.0",
    "postcss": "^8.0.0",
    "autoprefixer": "^10.0.0"
  }
}

Option 2: Use Compatibility Build (Legacy Projects)

For projects where upgrading PostCSS isn't feasible (e.g., Vue CLI 4, older Webpack versions):

bash
npm uninstall tailwindcss postcss autoprefixer
npm install -D tailwindcss@npm:@tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9

YARN USERS

bash
yarn add -D tailwindcss@npm:@tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9

Option 3: Use Tailwind CLI Instead

If PostCSS compatibility issues persist, use the Tailwind CLI:

bash
npm uninstall tailwindcss postcss autoprefixer
npm install -D tailwindcss@latest
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch

Update your package.json scripts:

json
{
  "scripts": {
    "build:css": "tailwindcss -i ./src/input.css -o ./dist/output.css",
    "watch:css": "tailwindcss -i ./src/input.css -o ./dist/output.css --watch"
  }
}

Option 4: Vue CLI Specific Solution

For Vue CLI projects, use the official Vue CLI plugin:

bash
npm uninstall tailwindcss postcss autoprefixer
vue add tailwind

TIP

The Vue CLI plugin automatically handles PostCSS configuration and compatibility issues.

Configuration Files

After installation, ensure proper configuration:

postcss.config.js:

js
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}

tailwind.config.js:

js
module.exports = {
  content: [
    "./index.html",
    "./src/**/*.{vue,js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

Troubleshooting

Node.js Version Compatibility

Ensure you're using a supported Node.js version (v12.22.0 or higher):

bash
node -v

If needed, upgrade Node.js and clear npm cache:

bash
npm cache clean -f

Rebuild Configuration Files

If issues persist, regenerate configuration files:

bash
npx tailwindcss init

Framework-Specific Solutions

For React with CRACO:

json
{
  "scripts": {
    "start": "concurrently \"npm run start:css\" \"react-scripts start\"",
    "start:css": "tailwindcss -o src/tailwind.css --watch",
    "build": "npm run build:css && react-scripts build",
    "build:css": "NODE_ENV=production tailwindcss -o src/tailwind.css -m"
  }
}

For Storybook: Install the PostCSS addon:

bash
npm install -D @storybook/addon-postcss

Update .storybook/main.js:

js
module.exports = {
  addons: [
    {
      name: '@storybook/addon-postcss',
      options: {
        postcssLoaderOptions: {
          implementation: require('postcss'),
        },
      },
    },
  ],
};

Migration to Tailwind CSS v4

Starting from Tailwind CSS v4, PostCSS 8.4+ is required, and the package structure has changed:

bash
npm install tailwindcss @tailwindcss/postcss postcss

V4 CHANGES

Tailwind CSS v4 separates PostCSS and CLI into dedicated packages (@tailwindcss/postcss and @tailwindcss/cli). Make sure to update your installation commands accordingly.

Conclusion

The "PostCSS plugin tailwindcss requires PostCSS 8" error typically resolves by either:

  1. Upgrading to PostCSS 8+ (recommended for new projects)
  2. Using the compatibility build (for legacy projects)
  3. Switching to Tailwind CLI (when PostCSS isn't required)
  4. Using framework-specific plugins (Vue CLI, Storybook)

Always ensure your Node.js version is current and consider rebuilding configuration files if issues persist after package updates.

For the latest information, consult the Tailwind CSS documentation and PostCSS 8 migration guide.