← All fixes
Tailwind v4: Cannot apply unknown utility class (@apply)
#167Error
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 yet0 worked0 didn't
Tried it yourself?
Related fixes
Tailwind classes not applied (no styles at all, or only some classes work)
#145Tailwind CSS utility classes have no effect; page renders unstyled or classes built from strings are missing in production
Tailwind classes not applying after upgrading to Tailwind CSS v4
#166Tailwind CSS v4: no styles generated / utility classes have no effect after upgrade
Tailwind styles work in dev but are missing in production build
#5Some Tailwind classes have no effect after npm run build / deploy, though they work with the dev server.