Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@apply space-x-* or space-y-* not working #1791

Closed
djrasmusp opened this issue May 18, 2020 · 12 comments
Closed

@apply space-x-* or space-y-* not working #1791

djrasmusp opened this issue May 18, 2020 · 12 comments

Comments

@djrasmusp
Copy link

djrasmusp commented May 18, 2020

When trying to use space-x-* or space-y-* I get an build error say:

Syntax error: @apply cannot be used with .space-x-4 because .space-x-4 either cannot be found, or its actual definition includes a pseudo-selector like :hover, :active, etc. If you're sure that .space-x-4 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.

The classes gets build in the css file, if I dont purge first, but it can be used with @apply

Im using Tailwindcss 1.4.6

@estevanmaito
Copy link
Contributor

Are you using any preprocessor? Could you share your tailwind.config.js and the file you import Tailwind styles (the @tailwind or @import rules)?

@djrasmusp
Copy link
Author

djrasmusp commented May 18, 2020

Im using autoprefixer and postcss...

And my config.js file looking like this :

const defaultTheme = require('tailwindcss/defaultTheme')
module.exports = {
  purge: {
    enabled: false,
    content: ['../../views/**/*.php'],
  },
  theme: {
    extend: {
      colors: {
        'primary': '#f7941d',
        'secondary': '#9a0f0d',
        'facebook': '#4267B2',
        'instagram': '#E1306C',
        'snapchat': '#FFFC00',
        'spotify': '#1DB954',
        'youtube': '#FF0000',
      },
      fontFamily: {
        sans: ['Inter var', ...defaultTheme.fontFamily.sans],
      },
      gridTemplateColumns: {
        'content': '1fr 30%',
      },
      gridTemplateRows: {
        '25': 'repeat(25, minmax(0, 1fr))',
      },
      gridRow: {
        'span-7' : 'span 7 / span 7',
      },
      boxShadow: {
        'widget-outline': '#f4f5f7 0 -3px 0 inset',
        'sidebar-widget-outline': '#fbfdfe 0 -3px 0 inset',
        'widget-focus': '#f7941d 0 -3px 0 inset',
      }
    }
  },
  plugins: [
    require('@tailwindcss/ui')
  ]
}

And my import file

@tailwind base;
@import "common/variables";

@tailwind components;

@import "common/global";
@import "components/buttons";
@import "components/comments";
@import "components/cookie_notice";
@import "components/forms";
@import "components/nowplaying";
@import "components/timetable";
@import "components/widgets";
@import "components/wp-classes";
@import "layouts/header"; <-- where i tried adding it 
@import "layouts/sidebar";
@import "layouts/footer";
@import "layouts/pages";
@import "layouts/posts";
@import "layouts/tinymce";

@tailwind utilities;

But maybe the problem lies in the TailwindUI rather than tailwindcss


Update: just tested with only Tailwindcss getting the same error

@Landish
Copy link

Landish commented May 18, 2020

Having the same issue.

Does not work divide utilities also.

@estevanmaito
Copy link
Contributor

estevanmaito commented May 18, 2020

Oh, I see it!

You're using an utility before it's available: https://tailwindcss.com/docs/using-with-preprocessors/#build-time-imports

Your @import "layouts/header"; makes use of space-x-*, but it is only available after @tailwind utilities or @import "tailwindcss/utilities";

Move the utilities up or your imported file below it.

@adamwathan
Copy link
Member

Duplicate of #1599.

@xaralis
Copy link

xaralis commented Jun 9, 2020

I still cannot make this working. I have ridiculously simple rule:

.social-icon-group {
  @apply space-x-1;
}

And have this included after utilities:

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

/**
* Custom components
*/
@import "./molecules/social-icon-group.pcss";

But my build still fails claiming:

Message:
    /Users/xaralis/Workspace/pirati-ui/source/css/molecules/social-icon-group.pcss:2:3: `@apply` cannot be used with `.space-x-1` because `.space-x-1` either cannot be found, or its actual definition includes a pseudo-selector like :hover, :active, etc. If you're sure that `.space-x-1` 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.

  1 | .social-icon-group {
> 2 |   @apply space-x-1;
    |   ^
  3 | }
  4 |

Can you help me?

@estevanmaito
Copy link
Contributor

Did you read the issue in the comment exactly above yours?

Duplicate of #1599.

@xaralis
Copy link

xaralis commented Jun 10, 2020

Did you read the issue in the comment exactly above yours?

Duplicate of #1599.

I did but didn't fully understood what the result is. Does it mean that @apply can't be used in combination with space-* utils? If that's the case, it should be clearly mentioned in the docs.

Thanks

@tjkohli
Copy link

tjkohli commented Jul 8, 2020

I have the same exact issue.

Loading:

@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';

and then

nav {
	@apply space-x-5 flex tracking-widest;
}

giving the error:

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

Any thoughts?

@adamwathan
Copy link
Member

Please see this issue it explains it all:

#1599

This just doesn’t work and will not work any time soon, it’s a limitation of @apply.

@nomadboy20
Copy link

any fix

@adamwathan
Copy link
Member

See experimental feature here:

#2159

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants