tailwindcss: [Utility class] class doesn't exist. If `[Utility class]` is a custom class, make sure it is defined within a `@layer` directive.
I have created a StackBlitz reproduction of the issue.
Describe the bug:
I had TailwindCSS version ^3.0.5 and wanted to upgrade to ^3.0.13. After upgrade, I saw a couple of errors in my console.
Specifically, Tailwind is not able to recognize @layer utilities with @apply anymore.
Steps to reproduce:
- Open the minimal reproduction
- See in
HelloWorld.vuethat I have@apply my-custom-class - Then open
src/css/tailwind.cssand see thatmy-custom-classis defined under@layer utilities - Run the app and Observe the error
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 5
- Comments: 15 (1 by maintainers)
Hey! See docs: https://tailwindcss.com/docs/functions-and-directives#using-apply-with-per-component-css
I also have broken classes from
@layer utilitiesin@applyafter upgrading from"tailwindcss": "^3.0.8"to"tailwindcss": "^3.0.15".Why is such big breaking change introduced in such minor patch? Or is it a bug?
Just in case someone comes across this issue while using tailwind with
@nuxt/uiand@nuxtjs/color-mode: Try moving@nuxt/uiabove@nuxtjs/tailwindcssand@nuxtjs/color-mode. This solved the issue for me.nuxt.config.ts
it was due to my bad usage of tailwind config. I wasn’t using the “extend” property, so It overwrote the whole base config
Hey Adam!
In the docs it says:
In
3.0.5though, Tailwind had the idea that this class exists! So the behavior was purposely changed in later versions.Also says:
I honestly don’t understand why what I am doing is weird:
I am creating utility classes for fonts so I don’t have to repeat classes for (font-size, font-weight etc) all over again. Plus, those fonts are specified as they are below from the designer in the style guide.
And I am creating those under
@layer utilitiesbecause:The reason why I am using
@applyinstead of just using the HTML markup, is because I don’t have access to that. The element I am targeting is inside the Component Framework:So personally I think, you have to bring back the ability to allow
@layer utilitiesto get accessed by@apply.I also don’t understand what is weird about using @apply. What is the alternative? Putting the tailwind class on every element?
Have the same issue when tried to set colors in tailwind config as css variables. Seems that things like
text-primary-700/30does not work with css varsThis worked for me 😍
This worked for me, but… WHY? hahahaha There’s a way to make nuxt/ui load first than the others by default after installing (without need to put him manually)?