Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailwind's directive @apply not working on Nuxt

I'm trying to use Tailwind in my brand new project, every utilitie works fine but the @apply one can't even compile.

Here is the error message:

Syntax Error: SyntaxError                                                                                                                                                                                                                                       friendly-errors 08:12:30

(5:5) `@apply` cannot be used with `.lg\:mt-0` because `.lg\:mt-0` either cannot be found, or its actual definition includes a pseudo-selector like :hover, :active, etc. If you're sure that `.lg\:mt-0` 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.

  3 | @import 'tailwindcss/components';
  4 | .navbar-item-link {
> 5 |     @apply text-xs mt-1 lg:mt-0 px-3 no-underline text-gray-600 rounded-full border-solid border border-gray-100 hover:border-blue-best-100;
    |     ^
  6 | }
  7 | /* purgecss end ignore */

My tailwind.css file:

/* purgecss start ignore */
@import 'tailwindcss/base';
@import 'tailwindcss/components';
.navbar-item-link {
    @apply text-xs mt-1 lg:mt-0 px-3 no-underline text-gray-600 rounded-full border-solid border border-gray-100 hover:border-blue-best-100;
}
/* purgecss end ignore */

@import 'tailwindcss/utilities';

I already have installed postcss cli and using the postcss.config.js like so:

module.exports = {
  plugins: [
    require("postcss-import"),
    require("tailwindcss"),
    require("autoprefixer")
  ]
};

But none of this works.

like image 236
Uriel Carneiro Avatar asked Apr 24 '20 11:04

Uriel Carneiro


1 Answers

You can not use the pseudo-classes prefix with the @apply method

Instead of this

.navbar-item-link {
    @apply text-xs mt-1 lg:mt-0 px-3 no-underline text-gray-600 rounded-full border-solid border border-gray-100 hover:border-blue-best-100;
}

You should use something like this:

// Normal State
.navbar-item-link {
    @apply text-xs mt-1 px-3 no-underline text-gray-600 rounded-full border-solid border border-gray-100;
}

// Hover State
navbar-item-link:hover{
    @apply border-blue-best-100;
}

// Large Screen
@screen lg {
    .navbar-item-link{
        @apply mt-0;
    }
}

Here are more info about it

https://tailwindcss.com/docs/extracting-components/#extracting-css-components-with-apply

https://tailwindcss.com/docs/functions-and-directives/#screen

like image 102
Enrique Chavez Avatar answered Oct 13 '22 08:10

Enrique Chavez