swc-project/swc · error · Error
EndTagWithUnclosedElements
EndTagWithUnclosedElements
Error message
Unexpected end tag for "body", but there were unclosed elements
What it means
HTML parse error: </body> was reached while elements opened inside body were still on the stack of open elements (other than the expected body/html). The parser records the error and proceeds with the standard </body> handling, closing remaining content.
Source
Thrown at crates/swc_html_parser/src/parser/mod.rs:2651
"dd" | "dt"
| "li"
| "optgroup"
| "option"
| "p"
| "rb"
| "rp"
| "rt"
| "rtc"
| "tbody"
| "td"
| "tfoot"
| "th"
| "thead"
| "tr"
| "body"
| "html"
) {
self.errors.push(Error::new(
token_and_info.span,
ErrorKind::EndTagWithUnclosedElements(atom!("body")),
));
break;
}
}
self.insertion_mode = InsertionMode::AfterBody;
}
// An end tag whose tag name is "html"
//
// If the stack of open elements does not have a body element in scope, this is
// a parse error; ignore the token.
//
// Otherwise, if there is a node in the stack of open elements that is not
// either a dd element, a dt element, an li element, an optgroup element, an
// option element, a p element, an rb element, an rp element, an rt element, anView on GitHub (pinned to 5176682b65)
Solutions
- Close all inner elements before </body>
- Check for omitted end tags earlier in the document
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_html_parser/src/parser/mod.rs:2651 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/ba59bb3b7a1f9d4a.
Report an issue: GitHub.