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

Angular引入Ng2SmartTableModule报非NgModule类(-996002)错误

问题场景

新建Angular项目后,执行yarn add ng2-smart-table安装依赖,在模块imports配置项中引入Ng2SmartTableModule时出现报错,具体信息如下:

  • 核心错误提示:'Ng2SmartTableModule' does not appear to be an NgModule class.(-996002),IDE类型提示为(alias) class Ng2SmartTableModule import Ng2SmartTableModule
  • 错误定位与触发原因:报错指向ng2-smart-table.module.d.ts(1, 22),通常为ng2-smart-table库声明的Ng2SmartTableModule未被ngcc正确处理,或库版本与Angular Ivy渲染引擎不兼容导致。
复现代码
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { Ng2SmartTableModule } from 'ng2-smart-table';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    Ng2SmartTableModule,
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}
解决方案

按优先级排序可选择以下方案修复:

  • 替换为官方维护的Ivy兼容版本
    原公开版ng2-smart-table长期未迭代适配高版本Angular,官方已发布适配Ivy的正式包,先执行命令卸载旧包:
    yarn remove ng2-smart-table
    安装适配Angular 12+版本的兼容包:
    yarn add @akveo/ng2-smart-table
    安装完成后将模块引入路径替换为import { Ng2SmartTableModule } from '@akveo/ng2-smart-table';,重启IDE与本地开发服务即可修复报错,无运行时兼容问题。
  • 手动触发ngcc编译依赖
    若需保留原有包版本,先删除项目根目录下的node_modules文件夹与yarn锁文件,重新执行yarn install安装依赖,安装完成后执行命令手动触发ngcc全量编译:
    npx ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points
    编译完成后在tsconfig.json的angularCompilerOptions配置中确认开启partial编译模式:
    {
      "angularCompilerOptions": {
        "compilationMode": "partial"
      }
    }
    
    重启开发服务即可。
  • 临时关闭严格校验(仅本地调试可用)
    若仅需临时跑通项目,可在tsconfig.json的angularCompilerOptions中添加"strictNgModuleMetadata": false关闭NgModule类校验。注意:该方案仅能消除IDE静态检查报错,可能引发运行时异常,禁止在生产环境使用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.28 03:01:08