cssangularsasstailwind-csstailwind-css-4

How to upgrade TailwindCSS?


I'm currently using Tailwind v3 in my Angular project (https://github.com/edissyum/opencapture/tree/dev_nch).

Today I tried 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 @tailwind base import 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": {}
  }
}

Solution

  • Although it's not explicitly stated in the question, after reading the comments, I thought it would be better to highlight an important change here as well.

    Deprecated: preprocessors support

    Sass, Less, and Stylus

    Tailwind CSS v4.0 is a full-featured CSS build tool designed for a specific workflow, and is not designed to be used with CSS preprocessors like Sass, Less, or Stylus.

    Think of Tailwind CSS itself as your preprocessor — you shouldn't use Tailwind with Sass for the same reason you wouldn't use Sass with Stylus.

    Since Tailwind is designed for modern browsers, you actually don't need a preprocessor for things like nesting or variables, and Tailwind itself will do things like bundle your imports and add vendor prefixes.

    Sorry for the inconvenience here, however right now we don't support migrating .scss or .less files. Doing so would require us to be able to understand the scss/sass and less syntax to make changes. But even if we do that, Tailwind CSS v4 isn't really compatible with these files anyway.

    I would recommend to see if you can rename the file(s) to .css and try again. You might notice that sometimes people use scss for features such as nested css, which should just work already in Tailwind CSS v4 (and modern browsers). So there is a good chance that you might not need .scss files at all.

    Again, sorry about the inconvenience here, but if you can migrate to normal .css files, then upgrading using the upgrade tool should just work.

    Simply put, TailwindCSS v4 removes the need for Sass and other preprocessors. The TailwindCSS v4 ecosystem can independently provide the functionality that these preprocessors offered.

    You can read about that in our compatibility guide but the short answer is that we do not support SCSS files with the Vite plugin. If you really need it for some reason, you can try to build your own SCSS implementation with the PostCSS plugin and by controlling the execution order but both SCSS and Tailwind CSS are pre-processors that extend CSS and cause a conflict in some areas, so that's not something that we can support unfortunately.