oxc-project/oxc · error · OxcDiagnostic
`defineEmits` is referencing locally declared variables.
Error message
`defineEmits` is referencing locally declared variables.
What it means
Emitted by run_once of the vue valid-define-emits rule (referencing_locally) when the defineEmits declaration references a variable declared locally in the SFC setup scope. The macro is compiled away and hoisted outside setup, so local references cannot be resolved and produce broken output.
Solutions
- Inline the referenced variable's value directly into defineEmits
- Import the declaration from another module so it resolves at module scope
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/vue/valid_define_emits.rs:35 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/0c525f3815758a10.
Report an issue: GitHub.
Appendix: source
Thrown at crates/oxc_linter/src/rules/vue/valid_define_emits.rs:35
}
fn called_multiple_times(span: Span, second_span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("`defineEmits` has been called multiple times.")
.with_help("combine all events into a single `defineEmits` call.")
.with_labels([
span.label("`defineEmits` is called here"),
second_span.label("`defineEmits` is called here too"),
])
}
fn events_not_defined(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Custom events are not defined.")
.with_help("Define at least one event in `defineEmits`.")
.with_label(span)
}
fn referencing_locally(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("`defineEmits` is referencing locally declared variables.")
.with_help("inline the variable or import it from another module.")
.with_label(span)
}
fn define_in_both(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Custom events are defined in both `defineEmits` and `export default {}`.")
.with_help("Remove `export default`.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct ValidDefineEmits;
declare_oxc_lint!(
/// ### What it does
///
/// Enforce valid usage of the `defineEmits` compiler macro in Vue.
///View on GitHub (pinned to e1e7af627c)