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

Angular 14集成Bootstrap 5模态框编译报错求助

解决Angular 14 + Bootstrap 5模态框编译错误:createComponent未找到

问题原因

当前安装的@ng-bootstrap/ng-bootstrap版本与Angular 14不兼容。createComponent是Angular 15及以上版本新增的API,高版本ng-bootstrap依赖该API,但Angular 14的@angular/core并未导出这个方法,因此触发编译报错。

解决步骤

  • 卸载当前版本的@ng-bootstrap/ng-bootstrap:
    npm uninstall @ng-bootstrap/ng-bootstrap
    
  • 安装适配Angular 14的ng-bootstrap版本(13.x系列):
    npm install @ng-bootstrap/ng-bootstrap@13
    
  • 重新编译项目:
    ng serve # 或 ng build
    

验证

检查package.json中@ng-bootstrap/ng-bootstrap的版本号应为^13.x.x,确认后重启开发服务即可解决报错。

报错信息:
/node_modules/@ng-bootstrap/ng-bootstrap/fesm2020/ng-bootstrap.mjs:17281:25-40 - Error: export 'createComponent' (imported as 'createComponent') was not found in '@angular/core' (possible exports: ANALYZE_FOR_ENTRY_COMPONENTS, ANIMATION_MODULE_TYPE, APP_BOOTSTRAP_LISTENER, APP_ID, APP_INITIALIZER, ApplicationInitStatus, ApplicationModule, ApplicationRef, Attribute, COMPILER_OPTIONS, CUSTOM_ELEMENTS_SCHEMA, ChangeDetectionStrategy, ChangeDetectorRef, Compiler, CompilerFactory, Component, ComponentFactory, ComponentFactoryResolver, ComponentRef, ContentChild, ContentChildren, DEFAULT_CURRENCY_CODE, DebugElement, DebugEventListener, DebugNode, DefaultIterableDiffer, Directive, ENVIRONMENT_INITIALIZER, ElementRef, EmbeddedViewRef, EnvironmentInjector, ErrorHandler, EventEmitter, Host, HostBinding, HostListener, INJECTOR, Inject, InjectFlags, Injectable, InjectionToken, Injector, Input, IterableDiffers, KeyValueDiffers, LOCALE_ID, MissingTranslationStrategy, ModuleWithComponentFactories, NO_ERRORS_SCHEMA, NgModule,...)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.23 10:45:31