#Tailwind v4

3 messages · Page 1 of 1 (latest)

misty foxBOT
#

Hi @barren citrus. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The issue you're encountering is related to how Tailwind CSS is being integrated with Astro using Vite. Let me clarify a few points and provide a corrected configuration:

  1. Tailwind CSS v4 is not yet released. The latest stable version of Tailwind CSS is v3.x.

  2. The way you're importing and using the Tailwind CSS plugin for Vite is incorrect in the Astro configuration.

Here's the correct way to set up Tailwind CSS with Astro:

  1. First, make sure you have installed the official Astro Tailwind integration:
npm install @astrojs/tailwind
  1. Then, update your Astro configuration as follows:
// @ts-check
import { defineConfig, envField } from "astro/config";
import tailwind from "@astrojs/tailwind";

// <https://astro.build/config>
export default defineConfig({
  output: "server",
  trailingSlash: "always",

  devToolbar: {
    enabled: false,
  },

  server: {
    port: 1234,
    host: true,
  },
  env: {
    schema: {
      AVATAR_DIR_URL: envField.string({
        context: "server",
        access: "public",
        optional: false,
      }),
    },
  },

  integrations: [tailwind()],
});

The key changes are:

  1. Import the Tailwind integration from @astrojs/tailwind instead of @tailwindcss/vite.
  2. Use the integrations array in the Astro config to add the Tailwind integration, instead of adding it to the Vite plugins.

This configuration should resolve the type error you were experiencing. The error occurred because you were trying to use the Vite plugin directly, which isn't the recommended way to integrate Tailwind with Astro.

#

For more information on configuring Tailwind CSS with Astro, you can refer to the Astro documentation on CSS and styling.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: