The issue can occur when using the Vite plugin, the PostCSS plugin, or even the CLI.
If I import TailwindCSS into my main CSS file (./src/index.css) and then try to use the @apply directive with any standard utility class, I get an error message.
@import url("tailwindcss");
@layer base {
*,
::after,
::before,
::backdrop,
::file-selector-button {
border-color: var(--color-gray-200, currentColor);
}
div {
scrollbar-color: var(--color-neutral-400) transparent;
}
body {
margin: 0;
display: flex;
flex-direction: column;
@apply bg-slate-50; /* Cannot apply unknown utility class `bg-slate-50`. */
/* And at this point, the build fails as a critical error. */
@apply text-neutral-700;
}
a {
@apply text-purple-900 hover:text-purple-700 hover:underline;
}
button {
cursor: pointer;
}
}
And at this point, along with the error message, I also get an automatic suggestion saying that the @reference directive is required when using it outside of the main CSS file (e.g., in CSS modules). But I don't think that's the solution in this case.
[plugin:@tailwindcss/vite:generate:serve] Cannot apply unknown utility class
bg-slate-50. Are you using CSS modules or similar and missing@reference? https://tailwindcss.com/docs/functions-and-directives#reference-directive <path_to>/src/index.css
@apply- Moni