Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

[v4] @apply inside Svelte 5 <style> not working as expected #15204

Closed
lucas-subli opened this issue Nov 27, 2024 · 0 comments
Closed

[v4] @apply inside Svelte 5 <style> not working as expected #15204

lucas-subli opened this issue Nov 27, 2024 · 0 comments

Comments

@lucas-subli
Copy link

lucas-subli commented Nov 27, 2024

What version of Tailwind CSS are you using?

tailwindcss: 4.0.0-beta.2
@tailwindcss/vite: 4.0.0-beta.2

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

svelte: 5.2.9
sveltekit: 2.8.5

What version of Node.js are you using?

v20.17.0

What browser are you using?

Chrome, Firefox

What operating system are you using?

Ubuntu 24.04

Reproduction URL

Public github:
https://github.com/lucas-subli/svelte-5-tailwind-4-beta

pnpm install
pnpm dev --open

Describe your issue

This code:

<h1 class="text-red-500">This is red</h1>
<h1 class="red">This should be red</h1>

<style>
  .red {
      @apply text-red-500;
  }
</style>

Generates this result:
image

With this error:

[plugin:vite-plugin-svelte] Error while preprocessing /home/lucas/Workspace/stuff/svelte-5-tailwind-4-beta/src/routes/+page.svelte - Cannot apply unknown utility class: text-red-500

@apply inside svelte <style> does not work properly.

After this PR: #14151
The below will work:

<style global>
  @import 'tailwindcss';

  .red {
      @apply text-red-500;
  }
</style>

However, flagging the style as global and importing 'tailwindcss' in every component I want to use @apply is not a reasonable solution.

The PR mentioned above also has a comment stating:

// In practice, it is not recommended to use `@tailwind utilities;` inside
// Svelte components. Use an external `.css` file instead.

However, this does not seem to work, as seen in the provided reproduction URL, where tailwind is imported by app.css and made available through +layout.svelte — as previously done with tailwind 3 + SvelteKit.

@tailwindlabs tailwindlabs locked and limited conversation to collaborators Nov 27, 2024
@adamwathan adamwathan converted this issue into discussion #15205 Nov 27, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant