swc-project/swc · error · swc_css_parser::Error
Unexpected at-rules are not allowed here
Error message
Unexpected at-rules are not allowed here
What it means
An at-rule appeared in a context where its block is not allowed (e.g. @import or @charset inside another rule's block); the parser rejects it at its span because those at-rules are only valid at the top level.
Source
Thrown at crates/swc_css_parser/src/parser/at_rules/mod.rs:582
}
"import" => {
let span = self.input.cur_span();
return Err(Error::new(span, ErrorKind::Unexpected("'{' token")));
}
"keyframes" | "-webkit-keyframes" | "-moz-keyframes" | "-o-keyframes"
| "-ms-keyframes" => {
let ctx = Ctx {
block_contents_grammar: BlockContentsGrammar::RuleList,
in_keyframes_at_rule: true,
..self.ctx
};
let rule_list = self.with_ctx(ctx).parse_as::<Vec<Rule>>()?;
let rule_list: Vec<ComponentValue> = rule_list
.into_iter()
.map(|rule| match rule {
Rule::AtRule(at_rule) => {
self.errors.push(Error::new(
at_rule.span,
ErrorKind::Unexpected("at-rules are not allowed here"),
));
ComponentValue::AtRule(at_rule)
}
Rule::QualifiedRule(qualified_rule) => {
let locv = match qualified_rule.prelude {
QualifiedRulePrelude::ListOfComponentValues(locv) => locv,
_ => {
unreachable!();
}
};
let res = self.parse_according_to_grammar(&locv, |parser| {
parser.input.skip_ws();
let child = parser.parse()?;View on GitHub (pinned to 5176682b65)
Solutions
- Move the at-rule to the stylesheet's top level
- Collect and report the error
- Drop the disallowed at-rule during recovery
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_css_parser/src/parser/at_rules/mod.rs:582 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/52571fcf27a1a694.
Report an issue: GitHub.