oxc-project/oxc · error · OxcDiagnostic
<{element}> is forbidden.
Error message
<{element}> is forbidden. What it means
Raised by react/forbid_elements when a JSX element or React.createElement tag name matches the rule's `forbid` configuration. At the throw site the element is one the project disallows (e.g. `<h1>`, `<img>`, or a component enforcing alternatives). The optional per-entry `message` from config becomes the help text; forbid_elements_diagnostic builds this message with the offending element name and is invoked from add_diagnostic_if_invalid_element during element traversal.
Source
Thrown at crates/oxc_linter/src/rules/react/forbid_elements.rs:23
use oxc_str::CompactStr;
use rustc_hash::FxHashMap;
use schemars::JsonSchema;
use serde::Deserialize;
use crate::{
AstNode,
context::{ContextHost, LintContext},
rule::{DefaultRuleConfig, Rule},
utils::{get_element_type, is_react_function_call},
};
fn forbid_elements_diagnostic(
element: &str,
help: Option<&CompactStr>,
span: Span,
) -> OxcDiagnostic {
if let Some(help) = help {
return OxcDiagnostic::warn(format!("<{element}> is forbidden."))
.with_help(help.to_string())
.with_label(span);
}
OxcDiagnostic::warn(format!("<{element}> is forbidden.")).with_label(span)
}
#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]
#[serde(from = "ForbidElementsConfig")]
pub struct ForbidElements {
// Map from element name to optional message for diagnostics.
forbid: Box<FxHashMap<CompactStr, Option<CompactStr>>>,
}
impl From<ForbidElementsConfig> for ForbidElements {
fn from(config: ForbidElementsConfig) -> Self {
// Convert Vec to FxHashMap.
// Later entries will override earlier ones for duplicates.View on GitHub (pinned to e1e7af627c)
Solutions
- Replace the forbidden element with an allowed alternative (often suggested by the configured help message).
- Remove the element from the forbid list if it should be permitted.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/react/forbid_elements.rs:23 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/5cae602f11e29c99.
Report an issue: GitHub.