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

Angular 17导入RatingModule报错:TS-996002问题求助

解决Angular 17导入RatingModule出现TS-996002错误

问题场景

在Angular 17项目中引入ng-starrating库的RatingModule时触发TS-996002错误,提示该类并非NgModule,核心原因是库与Angular Ivy架构不兼容。

导入代码:

import { RatingModule } from 'ng-starrating';
imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    RatingModule
  ],

错误详情:

TS-996002: 'RatingModule' does not appear to be an NgModule class. [plugin angular-compiler]

    src/app/app.module.ts:20:4:
      20 │     RatingModule
         ╵     ~~~~~~~~~~~~

  This likely means that the library (ng-starrating) which declares RatingModule is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.

    node_modules/ng-starrating/lib/rating.module.d.ts:1:21:
      1 │ export declare class RatingModule {

解决办法

  • 更新库版本:执行命令升级到最新版,确认是否已适配Ivy:
    npm update ng-starrating
    # 或直接安装最新版
    npm install ng-starrating@latest
    
  • 临时禁用Ivy(不推荐长期使用):在项目根目录的tsconfig.json中修改配置:
    "angularCompilerOptions": {
      "enableIvy": false
    }
    
    注意:Angular 17默认依赖Ivy,禁用后可能影响其他现代Angular特性。
  • 替换兼容库:选择维护活跃、适配新版本Angular的星评库,比如ngx-star-rating或angular-star-rating,按对应文档导入使用即可。
  • 反馈给作者:若更新后仍未解决,可在库的代码仓库提交Issue,询问Ivy适配计划。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 22:13:23