swc-project/swc · error · Error
End tag "{tag_name}" seen, but there were open elements
Error message
End tag "{tag_name}" seen, but there were open elements What it means
HTML parse error on an </li> end tag: 'li' is not in list item scope, or after generating implied end tags the current node was not an li, meaning the </li> closes through other still-open elements. The parser pops until an li is popped and records this error.
Source
Thrown at crates/swc_html_parser/src/parser/mod.rs:3361
// Generate implied end tags, except for li elements.
//
// If the current node is not an li element, then this is a parse error.
//
// Pop elements from the stack of open elements until an li element has been
// popped from the stack.
Token::EndTag { tag_name, .. } if tag_name == "li" => {
if !self.open_elements_stack.has_in_list_item_scope("li") {
self.errors.push(Error::new(
token_and_info.span,
ErrorKind::NoElementToCloseButEndTagSeen(tag_name.clone()),
));
} else {
self.open_elements_stack
.generate_implied_end_tags_with_exclusion("li");
match self.open_elements_stack.items.last() {
Some(node) if !is_html_element!(node, "li") => {
self.errors.push(Error::new(
token_and_info.span,
ErrorKind::UnclosedElements(tag_name.clone()),
));
}
_ => {}
}
let popped =
self.open_elements_stack.pop_until_tag_name_popped(&["li"]);
self.update_end_tag_span(popped.as_ref(), token_and_info.span);
}
}
// An end tag whose tag name is one of: "dd", "dt"
//
// If the stack of open elements does not have an element in scope that is an
// HTML element with the same tag name as that of the token, then this is a
// parse error; ignore the token.View on GitHub (pinned to 5176682b65)
Solutions
- Match each </li> with a proper <li> start tag
- Close intervening elements so lists are correctly nested
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_html_parser/src/parser/mod.rs:3361 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/e4812c0265b124ac.
Report an issue: GitHub.