swc-project/swc · error · Error

Unexpected end of file, but expected '}'

Error message

Unexpected end of file, but expected '}'

What it means

Fired while consuming a simple block opened with '{': EOF was reached before the matching '}' mirror token. Per CSS Syntax 5.4.7 this is a parse error; the parser returns the block built so far and records this error instead of aborting.

Source

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

            name,
            value: Vec::new(),
        };

        // Repeatedly consume the next input token and process it as follows:
        loop {
            // <EOF-token>
            // This is a parse error. Return the block.
            if is!(self, EOF) {
                let mirror = match &simple_block.name.token {
                    Token::LBracket => "']'",
                    Token::LParen => "')'",
                    Token::LBrace => "'}'",
                    _ => {
                        unreachable!();
                    }
                };

                self.errors.push(Error::new(
                    span!(self, span.lo),
                    ErrorKind::EofButExpected(mirror),
                ));

                break;
            }

            match cur!(self) {
                // ending token
                // Return the block.
                tok!("]") if simple_block.name.token == Token::LBracket => {
                    bump!(self);

                    break;
                }
                tok!(")") if simple_block.name.token == Token::LParen => {
                    bump!(self);

View on GitHub (pinned to 5176682b65)

Solutions

  1. Close the '{' block with a matching '}'
  2. Find an unclosed brace earlier in the file that swallows the intended closer
Defensive patterns

Strategy: fallback

When it happens

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