[v4] It looks like you're trying to use `tailwindcss` directly as a PostCSS plugin.
Problem
What version of Tailwind CSS are you using? 4.0.0 What build tool (or framework if it abstracts the build tool) are you using? "@tailwindcss/postcss": "^4.0.0", Angular 19.1.3 What version of Node.js are you using? 22.11.0 What browser are you using? Chrome newest version What operating system are you using? macOS M3 Pro Describe your issue Today I try to upgrade to Tailwind v4, but without success. I didn't use postcss, I just have Tailwind in my package.json, my tailwind.config.js and the @import tailwind in my main scss file. If I upgrade the package to 4.0.0, I have the following error: 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. I try to install @tailwind/postcss and create a PostCSS config file like this `export default { plugins: { "@tailwindcss/postcss": {} } }` Has anyone any idea how to fix this problem? On stackoverflow there is a similar question on this topic but the person is using the tailwind directive to import it. I've solved that but I still get the same error. Stackoverflow: https://stackoverflow.com/questions/79380519/how-to-upgrade-tailwindcss
Error Output
error: Error: It looks like you're trying to use `tailwindcss` directly as a PostCSS plugin.
Unverified for your environment
Select your OS to check compatibility.
2 Fixes
Fix Tailwind CSS PostCSS Configuration for v4 Upgrade
The error occurs because Tailwind CSS v4 has separated its PostCSS plugin into a distinct package, requiring users to explicitly install and configure it in their PostCSS setup. The previous method of using Tailwind directly in the PostCSS configuration is no longer valid.
Awaiting Verification
Be the first to verify this fix
- 1
Install the Correct PostCSS Plugin
You need to install the `@tailwindcss/postcss` package to use Tailwind CSS with PostCSS. This package is necessary for the Tailwind CSS v4 functionality.
bashnpm install @tailwindcss/postcss - 2
Create or Update PostCSS Configuration
Create a `postcss.config.js` file in the root of your project if it doesn't exist, or update it to include the new Tailwind CSS PostCSS plugin.
javascriptmodule.exports = { plugins: [ require('@tailwindcss/postcss'), require('autoprefixer'), ], }; - 3
Update Tailwind Import in SCSS
Ensure that your main SCSS file correctly imports Tailwind CSS using the `@tailwind` directive. This should remain unchanged but is crucial for proper functionality.
scss@import 'tailwindcss/base'; @import 'tailwindcss/components'; @import 'tailwindcss/utilities'; - 4
Rebuild Your Project
After making the above changes, rebuild your project to ensure that all configurations are applied and that the new PostCSS setup is recognized.
bashnpm run build - 5
Verify Tailwind CSS Functionality
Check your application in the browser to confirm that Tailwind CSS styles are being applied correctly and that the error no longer appears.
noneOpen your application in Chrome and inspect elements styled with Tailwind.
Validation
To confirm the fix worked, ensure that your application compiles without errors and that Tailwind CSS styles are applied correctly in the browser. You should no longer see the error message regarding using Tailwind CSS as a PostCSS plugin.
Sign in to verify this fix
1 low-confidence fix
Update Tailwind CSS Configuration for PostCSS Compatibility
The error occurs because Tailwind CSS v4.0.0 requires the use of the `@tailwindcss/postcss` package as a PostCSS plugin instead of using Tailwind directly. This change necessitates an update to your PostCSS configuration to properly integrate Tailwind CSS.
Awaiting Verification
Be the first to verify this fix
- 1
Install the Correct PostCSS Plugin
Ensure that you have the `@tailwindcss/postcss` package installed in your project. This package is necessary for Tailwind CSS to work as a PostCSS plugin.
bashnpm install @tailwindcss/postcss --save-dev - 2
Create or Update PostCSS Configuration File
Create a PostCSS configuration file named `postcss.config.js` in the root of your project if it doesn't exist. If it does exist, update it to include the `@tailwindcss/postcss` plugin.
javascriptmodule.exports = { plugins: { '@tailwindcss/postcss': {}, 'autoprefixer': {} } }; - 3
Update Tailwind Import in SCSS
Ensure that your main SCSS file correctly imports Tailwind CSS using the `@import` directive. This should remain unchanged, but confirm it is correctly set up.
scss@import 'tailwindcss/base'; @import 'tailwindcss/components'; @import 'tailwindcss/utilities'; - 4
Remove Old Tailwind CSS References
Check your project for any direct references to the old Tailwind CSS plugin in your build configuration or scripts and remove them to avoid conflicts.
javascript// Remove any direct tailwindcss references from your build scripts. - 5
Rebuild Your Project
After making the above changes, rebuild your project to ensure that all configurations are applied correctly.
bashnpm run build
Validation
To confirm the fix worked, run your build process and check for any errors. If the build completes successfully and Tailwind CSS styles are applied correctly in your application, the issue is resolved.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep