question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom class inside @apply

See original GitHub issue

Hello folks,

In tailwind.css file, I declare a custom class called “.flex-center” as seen above.

@layer base { .flex-center { display: flex; align-items: center; justify-content: center; } }

I can use that new custom class inside class prop of elements without any problem both on local development and nuxt build.

However when I use that class inside apply directive in a component as seen above, It works on local development phase, but fails in nuxt build.

<style lang="postcss" scoped>
li {
  @apply h-12 w-12 flex-center;
}
</style>

In nuxt build (it works on with nuxt local development), following error appears:

_

The flex-center class does not exist. If flex-center is a custom class, make sure it is defined within a @layer directive.

_

Now I’m using another approach without using custom class inside apply but I believe as nuxt tailwind community, we should fix it.

EDIT: After some research, I found this problem is not related with nuxt. In tailwind docs topic explained in detail.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

4reactions
maxmellencommented, Mar 15, 2022

Can confirm that I’m also running into this bug…

Dependency Versions:

1reaction
daviddarxcommented, Jun 28, 2022

Getting the same problem with <style lang="pcss" scoped> h1 { @apply test; } </style>

If I implement it directly in the template, on top of the .vue, it’s working: <h1 class="test">I am the about page</h1>

@nuxtjs/tailwindcss”: “^5.1.3”, “nuxt”: “3.0.0-rc.4”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom class inside @apply #415 - nuxt-modules/tailwindcss
I can use that new custom class inside class prop of elements without any problem both on local development and nuxt build.
Read more >
Reusing Styles - Tailwind CSS
Yes, HTML templates littered with Tailwind classes are kind of ugly. Making changes in a project that has tons of custom CSS is...
Read more >
How to add custom class to with @apply (Tailwind) in Angular ...
shadow-outline is a custom class. You must first define it before using it like this: @layer components { .shadow-outline { @apply w-auto ...
Read more >
Using @apply with Complex Classes – What's new in Tailwind ...
Tailwind CSS v2.0 makes it easier than ever to extract your own custom classes using "@ apply ", even when you need to...
Read more >
How to Apply Custom Class Styles in Cascading Style Sheets ...
Class styles, which are also sometimes called custom class styles , custom styles, or custom classes , in Cascading Style Sheets (CSS) are ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found