{"record":{"id":"5b8eab2ce3bfe36b","repo":"oxc-project/oxc","slug":"the-events-api-is-deprecated","errorCode":null,"errorMessage":"The Events api `{}` is deprecated.","messagePattern":"The Events api `(.+?)` is deprecated\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/vue/no_deprecated_events_api.rs","lineNumber":19,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Expression, MemberExpression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::Rule,\n    utils::{is_in_vue_component_instance_method, is_this_object},\n};\n\nconst DEPRECATED_EVENTS_API_METHODS: [&str; 3] = [\"$on\", \"$off\", \"$once\"];\n\nfn no_deprecated_events_api_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"The Events api `{}` is deprecated.\",\n        DEPRECATED_EVENTS_API_METHODS.join(\"`, `\")\n    ))\n    .with_help(\"Using external library instead, for example mitt.\")\n    .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoDeprecatedEventsApi;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow using deprecated Events API (`$on`, `$off`, `$once`) in Vue.js 3.0.0+.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// In Vue.js 3.0.0+, the internal event APIs `$on`, `$off`, and `$once` have been removed.","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vue/no_deprecated_events_api.rs#L1-L37","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","solutions":["Replace the event bus with mitt: import { mitt } from 'mitt'; const emitter = mitt(); emitter.on/off/emit","For parent-child flows, use props and emits (defineEmits) instead of imperative listeners","For app-level events, provide the emitter via app.provide or a dedicated module"],"exampleFix":"// before\neventBus.$on('refresh', this.load)\n// after\nimport { mitt } from 'mitt'\nconst emitter = mitt()\nemitter.on('refresh', this.load)","handlingStrategy":"validation","validationCode":"# find removed instance event methods\ngrep -rnE \"\\.\\$(on|off|once)\\(\" --include='*.vue' --include='*.js' src","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use mitt (or another emitter) for cross-component events; reserve props/emits for parent-child flows","Never build new event buses on component instances — the API is gone in Vue 3"],"tags":["vue","oxlint","lint","event-bus","vue3","migration","removed-api"],"backgroundTag":"vue-2-to-3-migration","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}