swc-project/swc · error · Error

No "{tag_name}" element in scope but a "{tag_name}" end tag

Error message

No "{tag_name}" element in scope but a "{tag_name}" end tag seen

What it means

HTML parse error: an end tag (e.g. </form> or </p>-class tags) was seen but no corresponding element exists in the required scope on the stack of open elements, so there is nothing to close. The tag name is embedded in the message; recovery follows the spec (ignore or synthesize the element).

Source

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

                            }

                            let popped = self
                                .open_elements_stack
                                .pop_until_tag_name_popped(&["form"]);

                            self.update_end_tag_span(popped.as_ref(), token_and_info.span);
                        }
                    }
                    // An end tag whose tag name is "p"
                    //
                    // If the stack of open elements does not have a p element in button scope, then
                    // this is a parse error; insert an HTML element for a "p" start tag token with
                    // no attributes.
                    //
                    // Close a p element.
                    Token::EndTag { tag_name, .. } if tag_name == "p" => {
                        if !self.open_elements_stack.has_in_button_scope("p") {
                            self.errors.push(Error::new(
                                token_and_info.span,
                                ErrorKind::NoElementToCloseButEndTagSeen(tag_name.clone()),
                            ));

                            self.insert_html_element(
                                &self.create_fake_token_and_info("p", Some(token_and_info.span)),
                            )?;
                        }

                        self.close_p_element(token_and_info, true);
                    }
                    // An end tag whose tag name is "li"
                    //
                    // If the stack of open elements does not have an li element in list item scope,
                    // then this is a parse error; ignore the token.
                    //
                    // Otherwise, run these steps:
                    //

View on GitHub (pinned to 5176682b65)

Solutions

  1. Remove the stray end tag
  2. Add the matching start tag or fix earlier structure so the element is in scope
Defensive patterns

Strategy: validation

When it happens

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