You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vue+TS项目集成vue-i18n@10出现类型不兼容错误求助

Vue-i18n 与 Vue 3 类型不兼容问题解决

问题背景

为高校项目实现多语言功能,选用vue-i18n方案,通过npm install vue-i18n@10.安装了v10.0.3版本。导入并调用createI18n创建实例后,执行app.use(i18n)时触发以下类型错误:

The argument of type ‘I18n<{}, {}, {}, string, true>’ is not assignable to the parameter of type ‘Plugin<[]>’.
  The type ‘I18n<{}, {}, {}, string, true>’ cannot be assigned to the type ‘{ install: (app: App<any>) => any; }’.
    Property types ‘install’ are incompatible.
      The type ‘(app: App<any>, ...options: unknown[]) => void’ cannot be assigned to the type ‘(app: App<any>) => any’.
        The parameter types ‘app’ and ‘app’ are incompatible.
          The ‘onUnmount’ property is missing in the type ‘import('c:/Projetos/pibic/Tutor_de_ensino_TS/aplicacao/frontend/node_modules/@vue/runtime-core/dist/runtime-core.) App<any>‘, but it is mandatory in the type “import("c:/Projetos/pibic/Tutor_de_ensino_TS/aplicacao/node_modules/@vue/runtime-core/dist/runtime-core’).App<any>'.ts(2345)
runtime-core.d.ts(1041, 5): ‘onUnmount’ is declared here.
const i18n: I18n<{}, {}, {}, string, true>

已尝试重新创建Vue项目测试,问题复现。当前项目依赖版本:

aplicacao@ C:\Projetos\pibic\Tutor_de_ensino_TS\aplicacao
└─┬ vue-i18n@10.0.3
  └─┬ vue@3.5.10
    └─┬ @vue/server-renderer@3.5.10
      └── vue@3.5.10 deduped

问题原因

vue-i18n@10.x系列是专为Vue 2.x设计的版本,其类型定义与Vue 3.x的App实例结构不兼容,导致install方法的参数类型匹配失败,触发上述错误。

解决方案

  1. 卸载当前不兼容的vue-i18n版本:
npm uninstall vue-i18n
  1. 安装适配Vue 3.x的vue-i18n版本(推荐v9.x稳定版):
npm install vue-i18n@9

安装完成后,重新导入createI18n并配置,即可正常执行app.use(i18n),类型错误将消失。

内容的提问来源于stack exchange,提问作者Guilherme Pereira

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 16:12:45