#Astro + React + Tailwind v4: “Unknown at rule @reference” & “Unknown at rule @apply”

2 messages · Page 1 of 1 (latest)

arctic mulch
#

Hello everyone,

I’m starting a new Astro project with React and Tailwind v4, but my CSS Modules aren’t picking up Tailwind’s @apply or my @reference. Here’s exactly what I’ve done:

Scaffold Astro

npm create astro@latest app
# Chose “Install recommended” → Yes  
# Chose “Install dependencies” → Yes  
# Chose “Create git repo” → No

Add React

npx astro add react
# Accepted all prompts

Add Tailwind

npx astro add tailwind
# Accepted all prompts

Global CSS (src/styles/global.css):

@import "tailwindcss";

Import global CSS in src/pages/index.astro:

---
import "../styles/global.css";
import Counter from "../components/Counter.jsx";
---
<html>
  <body>
    <Counter client:load />
  </body>
</html>

CSS Module (src/components/Counter.module.css):

@reference "../styles/global.css";

.counter {
  @apply flex items-center justify-center h-screen bg-gray-100;
}

Errors:

@reference Unknown at rule @reference
@apply     Unknown at rule @apply

Question:
Why aren’t my CSS Modules recognizing @reference and @apply? What configuration step am I missing?

Thanks in advance!

formal root
#

That definitely seems like it should be working! Would you mind sharing your Astro config?

Also I think it's important to note that tailwind itself does not recommend combining it and css modules for some pretty valid reasons so I would definitely keep that in mind houston_fingerguns