Custom utility: @apply can only be used for classes in the same CSS tree.
See original GitHub issueVersion
@nuxtjs/tailwindcss: v3.0.0
nuxt: 2.14.1
Reproduction Link
https://codesandbox.io/s/tailwindcss-issue-1jf8w
Steps to reproduce
Document: https://tailwindcss.com/docs/adding-new-utilities
In tailwind.pcss
, I create a custom class like:
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
@responsive {
.global-class {
@apply text-blue-400
}
}
The .global-class
or sm:global-class
can be use in <template>
.
But it can’t be use in <style lang="postcss">
with @apply
<style lang="postcss">
.component-class {
@apply text-blue-400; /* work */
}
.apply-component-class {
@apply component-class; /* work */
}
.apply-global-class {
@apply global-class; /* doesn't work, throw build error */
}
</style>
What is Expected?
@apply global-class;
will be work
What is actually happening?
@apply global-class;
throw build error
@apply
can only be used for classes in the same CSS tree.
Module build failed (from ./node_modules/postcss-loader/src/index.js): SyntaxError (26:3) `@apply` cannot be used with `.global-class` because `.global-class` either cannot be found, or its actual definition includes a pseudo-selector like :hover, :active, etc. If you're sure that `.global-class` exists, make sure that any `@import` statements are being properly processed *before* Tailwind CSS sees your CSS, as `@apply` can only be used for classes in the same CSS tree.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:24
Top Results From Across the Web
apply can only be used for classes in the same CSS tree. ...
Custom utility : @apply can only be used for classes in the same CSS tree. ... Document: https://tailwindcss.com/docs/adding-new-utilities.
Read more >tailwind: how to use @apply for custom class in nuxt2?
Fine, it seems to be a bug in nuxtjs/tailwindcss: Custom utility: @apply can only be used for classes in the same CSS tree.,...
Read more >Adding Custom Styles
Any custom styles you add to the base , components , or utilities layers will only be included in your compiled CSS if...
Read more >Tailwindcss SCSS error @apply class does not exist issue
I'm using SCSS in my project and all of the .scss files that I use the tailwind @apply in ... as `@apply` can...
Read more >the `@apply` class does not exist. if `@apply` is a custom ...
Using @apply in a Vue style block throws "class does not exist" error . ... sees your CSS, as `@apply` can only be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Check your
tailwind.config.js
file and ensure you’re properly nesting your object properties. I had the same issue, turns out I was missing the closing}
for mytheme
property.If anyone is getting an error in Vue SFC’s PostCSS blocks with custom utilities not ‘existing’, hopefully this will help:
This did NOT work (as a rule in a CSS file):
This DOES work (created as a plugin inside
tailwind.config.js
):Now I can do this in the SFC CSS (notice, you do not put a dot next to the custom class):
I hope this helps someone who is struggling to add custom utility classes to a Vue.js or Nuxt.js project.