swc-project/swc · error · Error

Expected '{'

Error message

Expected '{'

What it means

Same qualified-rule path as the EOF case: the input ended where the `{` starting the rule block is required, reported as EofButExpected("'{'") at the rule's start span. The stylesheet ends before the rule's block opens.

Source

Thrown at crates/swc_css_parser/src/parser/syntax/mod.rs:280

        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);
                    }
                }
                // <{-token>
                // Consume a simple block and assign it to the qualified rule’s block. Return the
                // qualified rule.
                tok!("{") => {
                    let block = self.parse_as::<SimpleBlock>()?;
                    let mut qualified_rule = QualifiedRule {
                        span: span!(self, span.lo),
                        prelude: QualifiedRulePrelude::ListOfComponentValues(
                            self.create_locv(prelude),
                        ),
                        block,
                    };

View on GitHub (pinned to 5176682b65)

Solutions

  1. Add the missing { } block for the rule
  2. Collect errors after parsing for diagnostics
  3. Fix the stylesheet
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_css_parser/src/parser/syntax/mod.rs:280 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/14f1127164fdb46b. Report an issue: GitHub.