Skip to content

[v4] Cannot apply unknown utility class X without @reference directive #15952

Description

@bcorcoran

What version of Tailwind CSS are you using?

v4.0.0

What build tool (or framework if it abstracts the build tool) are you using?

Vite 5.4.14

Describe your issue

In the upgrade guide for v4, the following is stated:

In v4, stylesheets that are bundled separately from your main CSS file (e.g. CSS modules files, <style> blocks in Vue, Svelte, or Astro, etc.) do not have access to theme variables, custom utilities, and custom variants defined in other files.

This makes it seem like you wouldn't have to use the @reference directive to include all util classes included out of the box with tailwindcss. That doesn't seem to be the case, as I had the following code:

<style>
.ui-multiselect-option em {
  @apply font-bold underline text-brand-blue-800;
}
.text-white .ui-multiselect-option em {
  @apply font-bold underline text-brand-blue-100;
}
</style>

The following error was thrown:

Cannot apply unknown utility class: font-bold

The issue is fixed by including the appropriate @reference directive. I would have expected to get an error on the text-brand-blue-* classes which were actually custom. Not sure if this is a bug or documentation issue, so reporting it as a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions