vite-plugin-windicss: `Semicolon or block is expected` CSS error when using `@apply` with any directive functions, when missing `svelte-windicss-preprocess`
Describe the bug

EDIT : Please read this if you come by this issue for the first time
If you also have the error Semicolon or block is expected, please try the steps in this comment below, which adds a potential temporary fix for svelte to stop spewing out errors, both in vscode and when trying to open your site.
The remaining issue with this is the fact that css seems to be outputted in a weird way, especially when using third party packages (Routify in my case), so some ways of working with WindiCSS aren’t fully functional.
If you want to take part of the journey where I pull my hair out, you can keep reading below, otherwise try the linked comment above and keep an eye out for an official statement on the resolution of this issue!
I’ve been pulling my hair out in these past few hours while trying to fix this issue.
While I know that it comes from svelte, I have successfully removed it by using svelte-windicss-preprocess, which prevents errors and actually compiles to something in the end. However, when using svelte-windicss-preprocess at the same time as vite-plugin-windicss, it seems like the css generation isn’t ideal, as the directives aren’t working :

(Tailwind UI’s default Navbar, which shouldn’t show the mobile hamburger menu in desktop mode. this doesn’t happen when the @apply css is commented out and svelte-windicss-preprocess is deactivated, as shown below)

Minimal Reproductions
Versions
-
vite-plugin-windicss: 0.9.4
-
vite: 2.1.2
-
framework(vue/react/svelte/etc): svelte
-
svelte-windicss-preprocess: 3.0.2
Additonal Context
I’m probably simply missing a configuration option, but I searched through a lot of windicss’s repos and different packages, and most issues that tackle this doesn’t seem to be containing a fix that worked for me.
I could provide a repo if desired.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 12
- Comments: 24 (6 by maintainers)
Commits related to this issue
- fix: preprocess for svelte — committed to windicss/vite-plugin-windicss by antfu 3 years ago
- Fix blog layout issue with complex class. Might be a bug: https://github.com/windicss/vite-plugin-windicss/issues/98#issuecomment-804222608 This doesn't seem to solve the issue, but looks related. — committed to CoryParsnipson/indie-engineer by CoryParsnipson 2 years ago
Did a quick investigation, it looks like the Svelte plugin does not emit the raw CSS content for other processors to transform before goes to Svelte’s own css compiler. And that’s possibly why it does not understand the
@applysyntax. I will keep work with @dominikg to see if we can find a solution for this.Should be fixed after https://github.com/sveltejs/vite-plugin-svelte/pull/13 got released.
It’s released https://github.com/sveltejs/vite-plugin-svelte/blob/main/packages/vite-plugin-svelte/CHANGELOG.md#100-next6
Having the same issue with svelte: The compile doesn’t let is pass.
One solution:
I’m experiencing the same issue. Here’s a minimal repro using this svite template
It’s a simple svelte app with no extra packages. You can see the changes I’ve made in the 2 commits that are on master. Basically, I’ve only upgraded all packages and added a style to make an element change background color on hover using @apply.
You can see the error by running
npm ithennpm run dev.Adding the configs mentioned in https://github.com/windicss/vite-plugin-windicss/issues/98#issuecomment-804222608 seems to fix it though.
Update : adding
important: trueto the tailwind / windicss configs helps with a lot of directives messing up the specificity…I still have some issues with conditional classes but I’ll keep trying to find ways around that
… I don’t see exactly how adding
!importantto all classes (with theimportantoption) fixes this issues, but css is a mystery yet to be unveiled. 😃I’ll look some more if there’s a universal-ish fix so that everything works with routify, I’ll keep this thread updated.
edit : while conditional classes work, using classes that
@applyies others doesn’t :bg-gray-900when active.activeand.inactiveyou can do what you want with this information (this probably goes a bit into the territory of #54) 😃
Actually @antfu, you might want to keep the
needs reproductionlabel, as I can’t repro it using a barebone svelte + vite + windicss project (with proper svelte.config) - it might be due to Routify or some other setup from my main repo.I’m still in the process of recreating my previous work in the second repo, where windicss works. I’ll keep updating this thread once I have more info.
You should try on your side to add windicss preprocess to svelte :
Add a
svelte.config.js, with this content :(add the missing packages if required)
Then, in your vite.config.ts` :
If you are using vscode with the svelte extension, don’t forget to reload the svelte language (
Svelte: Restart Language Server) or your vscode window.If everything looks the same, it might be fixed for you : I’m trying to figure out why does the output breaks so much, css-wise, in my first repro.