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

在另一Angular项目中使用自研Angular组件库时出现多种运行时错误

Angular自研组件库运行时错误排查

我在另一仓库的Angular应用中使用自研的Angular组件库,已解决所有编译时错误,但引入库中已声明并导出的组件时出现不同的运行时错误:

  • 使用简单的“外部链接”组件时,报错:TypeError: getLView() is null
  • 使用文本输入框包装组件时,报错:TypeError: tView is null
  • 使用相对复杂的列表视图组件时,报错:Error: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with EnvironmentInjector#runInContext``

组件库通过本地路径作为依赖安装到消费端项目,package.json配置示例:

"dependencies": {
  "atoms-lib": "file:../path/to/different/repo/dist/atoms-lib"
},

消费端应用的AppModule已导入该库的模块,代码如下:

import { AtomsLibModule } from 'atoms-lib';
@NgModule({
  declarations: [
    ...
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    AtomsLibModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

已完成以下排查:

  • 库与消费端应用的Angular版本匹配(均为Angular ^15.2.0)
  • 无论是库的部分Ivy编译模式还是完整Ivy编译模式,问题均存在

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 15:35:08