swc-project/swc · error · Error

StrayStartTag

StrayStartTag

Error message

Stray start tag "{tag_name}"

What it means

HTML parse error: a start tag that belongs in <body> was encountered in a context where it is not allowed (e.g. while still in head or another insertion mode), making it a 'stray' start tag. The tag name is included; the parser records the error and continues with spec recovery rules.

Source

Thrown at crates/swc_html_parser/src/parser/mod.rs:2260

                    // Process the token using the rules for the "in head" insertion mode.
                    Token::EndTag { tag_name, .. } if tag_name == "template" => {
                        self.process_token_using_rules(token_and_info, InsertionMode::InHead)?;
                    }
                    // An end tag whose tag name is one of: "body", "html", "br"
                    //
                    // Act as described in the "anything else" entry below.
                    Token::EndTag { tag_name, .. }
                        if matches!(&**tag_name, "body" | "html" | "br") =>
                    {
                        anything_else(self, token_and_info)?;
                    }
                    // A start tag whose tag name is "head"
                    //
                    // Any other end tag
                    //
                    // Parse error. Ignore the token.
                    Token::StartTag { tag_name, .. } if tag_name == "head" => {
                        self.errors.push(Error::new(
                            token_and_info.span,
                            ErrorKind::StrayStartTag(tag_name.clone()),
                        ));
                    }
                    Token::EndTag { tag_name, .. } => {
                        self.errors.push(Error::new(
                            token_and_info.span,
                            ErrorKind::StrayEndTag(tag_name.clone()),
                        ));
                    }
                    // Anything else
                    //
                    // Insert an HTML element for a "body" start tag token with no attributes.
                    //
                    // Switch the insertion mode to "in body".
                    //
                    // Reprocess the current token.
                    _ => {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Place the element inside <body> where it is valid
  2. Restructure the document so the tag appears in an appropriate insertion context
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_html_parser/src/parser/mod.rs:2260 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/861f04463604c0a7. Report an issue: GitHub.