oxc-project/oxc · error · OxcDiagnostic

The Events api `{}` is deprecated.

Error message

The Events api `{}` is deprecated.

What it means

Diagnostic from oxlint's vue/no-deprecated-events-api rule (since oxlint 1.62.0). It fires on the component-instance event emitter methods $on, $off, $once (DEPRECATED_EVENTS_API_METHODS), typically used to build event buses. Vue 3 removed the emitter interface from component instances entirely — these calls throw at runtime — and the help text suggests an external library such as mitt.

Source

Thrown at crates/oxc_linter/src/rules/vue/no_deprecated_events_api.rs:19

use oxc_ast::{
    AstKind,
    ast::{Expression, MemberExpression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{
    AstNode,
    context::LintContext,
    rule::Rule,
    utils::{is_in_vue_component_instance_method, is_this_object},
};

const DEPRECATED_EVENTS_API_METHODS: [&str; 3] = ["$on", "$off", "$once"];

fn no_deprecated_events_api_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "The Events api `{}` is deprecated.",
        DEPRECATED_EVENTS_API_METHODS.join("`, `")
    ))
    .with_help("Using external library instead, for example mitt.")
    .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct NoDeprecatedEventsApi;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow using deprecated Events API (`$on`, `$off`, `$once`) in Vue.js 3.0.0+.
    ///
    /// ### Why is this bad?
    ///
    /// In Vue.js 3.0.0+, the internal event APIs `$on`, `$off`, and `$once` have been removed.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace the event bus with mitt: import { mitt } from 'mitt'; const emitter = mitt(); emitter.on/off/emit
  2. For parent-child flows, use props and emits (defineEmits) instead of imperative listeners
  3. For app-level events, provide the emitter via app.provide or a dedicated module

Example fix

// before
eventBus.$on('refresh', this.load)
// after
import { mitt } from 'mitt'
const emitter = mitt()
emitter.on('refresh', this.load)
Defensive patterns

Strategy: validation

Validate before calling

# find removed instance event methods
grep -rnE "\.\$(on|off|once)\(" --include='*.vue' --include='*.js' src

Prevention

When it happens

Trigger: A member call on this (is_this_object) or inside a Vue component instance method (is_in_vue_component_instance_method) whose property name is $on, $off, or $once; the message interpolates all three names as `$on`, `$off`, `$once`.

Common situations: Vue 2 global event buses (eventBus.$on(...)), cross-component communication via this.$root.$once, or plugin code wiring listeners on component instances; all break with 'is not a function' errors after upgrading to Vue 3.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/5b8eab2ce3bfe36b. Report an issue: GitHub.