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

[v4] Files imported with @import "…" theme(…) must only contain @theme blocks #15219

Open
amir20 opened this issue Nov 28, 2024 · 3 comments · May be fixed by #15228
Open

[v4] Files imported with @import "…" theme(…) must only contain @theme blocks #15219

amir20 opened this issue Nov 28, 2024 · 3 comments · May be fixed by #15228
Labels

Comments

@amir20
Copy link

amir20 commented Nov 28, 2024

What version of Tailwind CSS are you using?

tailwindcss 4.0.0-beta.2

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

vite 6.0.1

What version of Node.js are you using?

v23.1.0

What browser are you using?

NA

What operating system are you using?

macOS

Reproduction URL

I am not sure how to create Vue components with Tailwind Play. I have a reproducible example locally with only a few files.

  1. Created a new blank project using vite with Vue. eg npm create vite@latest
  2. Followed the directions to add Tailwind v4.
  3. Update Vue css to have @import
<style scoped>
@import "../style.css" theme(reference);

.test {
    @apply mb-4 bg-foo;
}
</style>

styles.css

@import "tailwindcss";

@theme {
    --color-foo: oklch(0.99 0 0);
}

@layer {
}

Describe your issue

build throws the following exception:

vite v6.0.1 building for production...
✓ 12 modules transformed.
x Build failed in 84ms
error during build:
[@tailwindcss/vite:generate:build] Files imported with `@import "…" theme(…)` must only contain `@theme` blocks.
file: /Users/amirraminfar/Desktop/my-project/src/components/HelloWorld.vue?vue&type=style&index=0&scoped=0cb914fb&lang.css
    at file:///Users/amirraminfar/Desktop/my-project/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/dist/lib.mjs:24:2929
    at D (file:///Users/amirraminfar/Desktop/my-project/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/dist/lib.mjs:3:3654)
    at D (file:///Users/amirraminfar/Desktop/my-project/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/dist/lib.mjs:3:3812)
    at D (file:///Users/amirraminfar/Desktop/my-project/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/dist/lib.mjs:3:3604)
    at D (file:///Users/amirraminfar/Desktop/my-project/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/dist/lib.mjs:3:3604)
    at D (file:///Users/amirraminfar/Desktop/my-project/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/dist/lib.mjs:3:3604)
    at file:///Users/amirraminfar/Desktop/my-project/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/dist/lib.mjs:24:2887
    at D (file:///Users/amirraminfar/Desktop/my-project/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/dist/lib.mjs:3:3654)
    at D (file:///Users/amirraminfar/Desktop/my-project/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/dist/lib.mjs:3:3604)
    at D (file:///Users/amirraminfar/Desktop/my-project/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/dist/lib.mjs:3:3604)
 ELIFECYCLE  Command failed with exit code 1.

Note: This was originally found in my project. So I created a small example using npm create vite@latest and it is still happening.

@amir20 amir20 changed the title Files imported with @import "…" theme(…) must only contain @theme blocks [v4] Files imported with @import "…" theme(…) must only contain @theme blocks Nov 28, 2024
@adamwathan
Copy link
Member

Hey! Solution for now is to move your custom @theme stuff to a separate file and then do this:

<style scoped>
@import "tailwindcss/theme" theme(reference);
@import "../custom-theme.css" theme(reference);

.test {
    @apply mb-4 bg-foo;
}
</style>

This definitely sucks though after using it ourselves so I want to make it possible to just do this:

<style scoped>
@import "../style.css" reference;

.test {
    @apply mb-4 bg-foo;
}
</style>

...especially since there could be other things defined in there that need to be available like custom @utility and @variant definitions.

@Alma219Way
Copy link

Alma219Way commented Nov 28, 2024

Hello!
The solution worked for me thanks to the community and the members for the solution. Prepaid Gift Balance

@amir20
Copy link
Author

amir20 commented Nov 28, 2024

Thanks @adamwathan! For my actual project, I am using @config '../tailwind.config.ts';. So I'll have to see if this works.

Agreed that this is definitely not ideal. Hopefully, no @import are needed in the future. Related discussion #15205

@philipp-spiess philipp-spiess linked a pull request Dec 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants