swc-project/swc · error · Error
Unexpected end of file, but expected '{'
Error message
Unexpected end of file, but expected '{' What it means
Fired while parsing a QualifiedRule per the CSS qualified-rule consumption algorithm: the token stream hit EOF before the rule's '{ ... }' block was found, so the rule is unterminated. Input at fault is a truncated stylesheet fragment such as `div { color: red` where the closing context never appears.
Source
Thrown at crates/swc_css_parser/src/parser/syntax/mod.rs:266
impl<I> Parse<QualifiedRule> for Parser<I>
where
I: ParserInput,
{
fn parse(&mut self) -> PResult<QualifiedRule> {
// To consume a qualified rule:
// Create a new qualified rule with its prelude initially set to an empty list,
// and its value initially set to nothing.
let span = self.input.cur_span();
let mut prelude = Vec::new();
// Repeatedly consume the next input token:
loop {
// <EOF-token>
// This is a parse error. Return nothing.
if is!(self, EOF) {
return Err(Error::new(
span!(self, span.lo),
ErrorKind::EofButExpected("'{'"),
));
}
match cur!(self) {
// <semicolon-token>
// If mixed with declarations is true, this is a parse error; return nothing.
// Otherwise, append a <semicolon-token> to the qualified rule’s prelude.
tok!(";") => {
if self.ctx.mixed_with_declarations {
let span = self.input.cur_span();
return Err(Error::new(span, ErrorKind::Expected("'{'")));
} else {
let component_value = self.parse_as::<ComponentValue>()?;
prelude.push(component_value);View on GitHub (pinned to 5176682b65)
Solutions
- Close the qualified rule with a { ... } block
- Surface the error from the parse result
- Fix the truncated CSS
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_css_parser/src/parser/syntax/mod.rs:266 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/75fd4ebeeee1c6f7.
Report an issue: GitHub.