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

Single SPA共享Angular独立组件:导入类型错误问题求助

问题描述

搭建了Single SPA + 3个Angular应用的架构,其中一个Angular应用名为ui-kit,目标是导出其独立组件供另外两个应用共享。

在ui-kit应用的main.single-spa.ts中做了如下导出:

// main.single-spa.ts - Ui Kit app
export * from './app/button/button.component';

在Angular App 1的app.component中导入ButtonComponent并添加到imports数组时,触发以下错误:

'imports' must be an array of components, directives, pipes, or NgModules. Value is of type '[RouterOutlet, undefined]'

奇怪的是,在ngOnInit中打印ButtonComponent能得到正确的Angular组件类,因此推测是类型定义问题。尝试了两种declarations.d.ts写法,但问题仍未解决:

第一种declarations.d.ts写法

declare module '@shared/ui-kit' {
  import { Type } from '@angular/core';

  export const ButtonComponent: Type<any>;
  export function getData(data: string): string;
}

第二种declarations.d.ts写法

declare module '@shared/ui-kit';

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 17:55:59