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

Angular集成ngx-translate报错:Type TranslateModule does not have 'ɵmod' property

问题原因

该错误本质是 @ngx-translate/core、@ngx-translate/http-loader 的版本与你项目的 Angular 大版本不兼容导致,ngx-translate 要求主版本号必须和 Angular 主版本号匹配。

解决步骤

  • 第一步:执行命令查看当前项目的 Angular 版本,记录 @angular/core 对应的大版本号
ng version
  • 第二步:卸载已安装的不匹配依赖
npm uninstall @ngx-translate/core @ngx-translate/http-loader
  • 第三步:按照版本对应规则安装匹配的依赖,版本对应关系如下:
Angular 版本@ngx-translate/core 版本@ngx-translate/http-loader 版本
13.x14.x7.x
14.x14.x7.x
15.x15.x8.x
16.x16.x9.x
17.x15.x/16.x8.x/9.x

举个例子,如果你的 Angular 版本是14,执行以下命令安装:

npm install @ngx-translate/core@14 @ngx-translate/http-loader@7 --save
  • 第四步:修正 app.module.ts 中的i18n文件路径配置,你当前写的相对路径多回退了一级,会导致后续加载不到翻译文件,修改为:
export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http,'./assets/i18n/','.json');
}
  • 第五步:清理缓存重启服务
    删除项目根目录下的 node_modules 文件夹和 package-lock.json 文件,重新执行 npm install 安装依赖,再执行 ng serve 启动项目即可解决报错。

内容的提问来源于stack exchange,提问作者Juan MP

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.08 05:30:03