angular – 当ng build –prod(AOT)时,装饰器不支持函数调用
问题类型:错误/问题
描述 我正在使用ng-packagr lib将我的库编译为js.我编译了所有内容没有任何问题,但是当我想要使用ng build –prod(启用AOT)来使用我的库时,我收到错误: 在“AppModule”的模板编译期间出现错误错误在装饰器中不支持函数调用,但调用了“BsDropdownModule”. 当我删除.forRoot方法时,我收到错误: ERROR in:由模块导入的/home/sf/Desktop/Developerka/kompilacja/final/sample-repo/node_modules/angular-library-name/free/dropdown/dropdown.module.d.ts’中的意外值’BsDropdownModule’ AppModule位于/home/sf/Desktop/Developerka/kompilacja/final/sample-repo/src/app/app.module.ts’.请添加@NgModule注释 请注意,ng –prod –aot = false 如何重现: 下载repo:https://github.com/Bloodcast69/aot-error,输入 预期的行为 想用AOT构建没有错误(我需要它与Angular Universal兼容) ng-packagr:2.4.1 文件: app.module.ts: import { BsDropdownModule } from 'angular-library-name'; import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ],imports: [ BsDropdownModule.forRoot(),BrowserModule ],providers: [],bootstrap: [AppComponent] }) export class AppModule { } dropdown.module.d.ts: import { ModuleWithProviders } from '@angular/core'; export declare class BsDropdownModule { static forRoot(config?: any): ModuleWithProviders; } dropdown.module.ts(在编译成JS之前): import { ModuleWithProviders,NgModule } from '@angular/core'; import { ComponentLoaderFactory } from '../utils/component-loader/index'; import { PositioningService } from '../utils/positioning/index'; import { BsDropdownContainerComponent } from './dropdown-container.component'; import { BsDropdownMenuDirective } from './dropdown-menu.directive'; import { BsDropdownToggleDirective } from './dropdown-toggle.directive'; import { BsDropdownConfig } from './dropdown.config'; import { BsDropdownDirective } from './dropdown.directive'; import { BsDropdownState } from './dropdown.state'; @NgModule({ declarations: [ BsDropdownMenuDirective,BsDropdownToggleDirective,BsDropdownContainerComponent,BsDropdownDirective ],exports: [ BsDropdownMenuDirective,entryComponents: [BsDropdownContainerComponent] }) export class BsDropdownModule { public static forRoot(config?: any): ModuleWithProviders { return { ngModule: BsDropdownModule,providers: [ ComponentLoaderFactory,PositioningService,BsDropdownState,{provide: BsDropdownConfig,useValue: config ? config : {autoClose: true}} ] }; }; } 注意 FeatureModule fails during an AOT build when static forRoot has arguments https://github.com/angular/angular/issues/14707 如果缺少一些必要的信息,请告诉我,我会提供. 谢谢, 解决方法
这是AOT的一个问题:forRoot函数需要在编译时执行.在更新版本的Angular上它应该按原样运行,否则你可能会运气玩tsconfig.app.json.检查此相关问题:
Angular 6 Prod Function calls are not supported in decorators but ‘..Module’ was called
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |