swc-project/swc · warning · Error

Saw a start tag "image", "img" element is outdated

Error message

Saw a start tag "image", "img" element is outdated

What it means

A start tag `image` was seen (parser/mod.rs:3883-3897). `image` is not an HTML element — it is a historical alias some old browsers accepted — so the spec says: parse error, rename the token's tag to `img`, and reprocess it. The parser mutates `*tag_name = atom!("img")` in place, so the output tree contains an `<img>` element, but the error records that the source used the legacy spelling.

Source

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

                        if self.open_elements_stack.has_in_button_scope("p") {
                            self.close_p_element(token_and_info, false);
                        }

                        self.insert_html_element(token_and_info)?;
                        self.open_elements_stack.pop();

                        if is_self_closing {
                            token_and_info.acknowledged = true;
                        }

                        self.frameset_ok = false;
                    }
                    // A start tag whose tag name is "image"
                    //
                    // Parse error. Change the token's tag name to "img" and reprocess it. (Don't
                    // ask.)
                    Token::StartTag { tag_name, .. } if tag_name == "image" => {
                        self.errors.push(Error::new(
                            token_and_info.span,
                            ErrorKind::UnexpectedImageStartTag,
                        ));

                        match token_and_info {
                            TokenAndInfo {
                                token: Token::StartTag { tag_name, .. },
                                ..
                            } => {
                                *tag_name = atom!("img");
                            }
                            _ => {
                                unreachable!();
                            }
                        }

                        self.process_token(token_and_info, None)?;
                    }

View on GitHub (pinned to 5176682b65)

Solutions

  1. Rename `<image>` to `<img>` in the source markup
  2. Grep your content pipeline for `<image` and fix generators/templates
  3. If ingesting legacy archives, accept the auto-correction (output tree is already `<img>`) and just log the error
  4. Add a content-lint rule rejecting `image` as a tag name

Example fix

<!-- before -->
<image src="logo.png" alt="Logo">

<!-- after -->
<img src="logo.png" alt="Logo">
Defensive patterns

Strategy: validation

Validate before calling

// Replace the legacy alias before parsing
fn normalize_image_tags(src: &str) -> String {
    src.replace("<image", "<img").replace("</image", "</img>") // img is void; end tag won't occur in valid input
}

Type guard

fn is_legacy_image_tag(e: &Error) -> bool {
    matches!(e.kind, ErrorKind::UnexpectedImageStartTag)
}

Try / catch

let doc = parser.parse_document()?;
let legacy = parser.take_errors().into_iter().filter(is_legacy_image_tag).count();
if legacy > 0 { log::info!("{legacy} <image> tags auto-renamed to <img>"); } // tree already correct

Prevention

When it happens

Trigger: Input containing `<image src="...">`. Any `image` start tag hits this arm; attributes are kept and carried over to the synthesized `<img>`.

Common situations: Legacy documents from the 1990s, OCR/scraped content, and user-authored HTML where people type `<image>` thinking of the noun. Also seen when Word/old editors export HTML.

Related errors


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/b10b9dcf8f866272. Report an issue: GitHub.