DioxusLabs/dioxus · error
css_module can only be applied to unit structs
Error message
css_module can only be applied to unit structs
What it means
`#[css_module]` requires the annotated struct to be a unit struct; this compile error is emitted when the struct has any fields. Fields have no meaning for a CSS module handle, so a struct with fields is rejected.
Solutions
- Apply the css_module attribute to a unit struct (e.g. `struct Styles;`); structs with fields are not supported.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/manganis/manganis-macro/src/css_module.rs:47 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23).
Data as JSON: /api/errors/3dc7047c0d7ebcca.
Report an issue: GitHub.
Appendix: source
Thrown at packages/manganis/manganis-macro/src/css_module.rs:47
}
let asset_parser = AssetParser {
path_expr,
asset,
options,
};
Ok(Self { asset_parser })
}
}
pub(crate) fn expand_css_module_struct(
tokens: &mut proc_macro2::TokenStream,
attribute: &CssModuleAttribute,
item_struct: &ItemStruct,
) {
if !item_struct.fields.is_empty() {
let err = syn::Error::new(
item_struct.fields.span(),
"css_module can only be applied to unit structs",
)
.into_compile_error();
tokens.append_all(err);
return;
}
if !item_struct.generics.params.is_empty() {
let err = syn::Error::new(
item_struct.generics.span(),
"css_module cannot be applied to generic structs",
)
.into_compile_error();
tokens.append_all(err);
return;
}
let struct_vis = &item_struct.vis;
let struct_name = &item_struct.ident;View on GitHub (pinned to 24f6a829df)