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

Angular 14引入ngx-doc-viewer遇TS2707错误求助

Angular 14 搭配 ngx-doc-viewer v15.0.0 报 TS2707 错误的解决办法

问题根源

你遇到的TS2707: Generic type 'ɵɵComponentDeclaration' requires between 7 and 8 type arguments错误,核心是版本不兼容:ngx-doc-viewer v15.0.0 是为 Angular 15 开发的,它使用的 Angular 内部编译器 API(比如ɵɵComponentDeclaration)参数数量与 Angular 14 的版本不一致,导致 TypeScript 类型检查失败。

解决步骤

  • 卸载当前不兼容的版本:
    npm uninstall ngx-doc-viewer
    
  • 安装适配 Angular 14 的 ngx-doc-viewer 版本(选择 v14 系列):
    npm install ngx-doc-viewer@14 --save
    
  • 保留原有的代码配置不变:
    • 模块中正常导入NgxDocViewerModule
    • 模板代码沿用之前的写法:
      <ngx-doc-viewer url="https://calibre-ebook.com/downloads/demos/demo.docx" viewer="google" style="width:100%;height:93vh;">
      </ngx-doc-viewer>
      
  • 重新编译项目,执行ng serve或ng build,该错误即可消除。

补充提醒

多数 Angular 第三方库的大版本号会与 Angular 主版本号对齐(比如 v14 对应 Angular 14,v15 对应 Angular 15),后续安装第三方库时优先选择与当前 Angular 版本匹配的大版本,能避免类似兼容性问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 17:55:07