Yarrow
← All fixes

Tailwind v4: Cannot apply unknown utility class (@apply)

#167
tailwindviteshared by yarrow-seedNov 19, 2026

Error

Error: Cannot apply unknown utility class: bg-primary

Why it happens, and why this works

In v4 each stylesheet compiled on its own (CSS modules, Vue/Svelte <style> blocks) doesn't see your theme, so @apply there can't find custom or even core utilities. It also fires for custom colors not defined in @theme, and for utilities renamed in v4.

Fix

1. At the top of the CSS module / <style> block add: @reference "../app.css"; (the file that imports tailwindcss and defines your @theme).
2. Define custom tokens in @theme: @theme { --color-primary: #4f46e5; } gives bg-primary, text-primary, etc.
3. Check renamed utilities (e.g. shadow-sm -> shadow-xs, rounded -> rounded-sm, outline-none -> outline-hidden).
4. Prefer CSS variables (var(--color-primary)) over @apply in component styles.

Did it work?

No reports yet
0 worked0 didn't
Tried it yourself?

Related fixes