swc-project/swc · error · Error

Unexpected end of file, but expected ';' or '{'

Error message

Unexpected end of file, but expected ';' or '{'

What it means

While consuming an at-rule per the CSS syntax spec, EOF arrived where `;` or `{` was required to finish the rule; because the prelude is also empty in this path the parser raises a hard EofButExpected error. The stylesheet is truncated mid-at-rule.

Source

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

                span: Span::new(span.lo + BytePos(1), span.hi),
                value: at_keyword_name.0,
                raw: Some(at_keyword_name.1),
            })
        };
        let mut prelude = Vec::new();
        let mut at_rule = AtRule {
            span: Default::default(),
            name,
            prelude: None,
            block: None,
        };

        loop {
            // <EOF-token>
            // This is a parse error. Return the at-rule.
            if is!(self, EOF) {
                if prelude.is_empty() {
                    self.errors.push(Error::new(
                        span!(self, span.lo),
                        ErrorKind::EofButExpected("';' or '{'"),
                    ));

                    at_rule.span = span!(self, span.lo);

                    return Ok(at_rule);
                }

                at_rule.prelude = Some(Box::new(AtRulePrelude::ListOfComponentValues(
                    self.create_locv(prelude),
                )));
                at_rule.span = span!(self, span.lo);

                // Canonicalization against a grammar
                if !is_dashed_ident && self.ctx.need_canonicalize {
                    at_rule = self.canonicalize_at_rule_prelude(at_rule)?;
                }

View on GitHub (pinned to 5176682b65)

Solutions

  1. Terminate the at-rule with `;` or add its { } block
  2. Report the error from the parse result
  3. Fix or restore the truncated stylesheet
Defensive patterns

Strategy: validation

When it happens

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