加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 当ng build –prod(AOT)时,装饰器不支持函数调用

发布时间:2020-12-17 06:59:38 所属栏目:安全 来源:网络整理
导读:问题类型:错误/问题 描述 我正在使用ng-packagr lib将我的库编译为js.我编译了所有内容没有任何问题,但是当我想要使用ng build –prod(启用AOT)来使用我的库时,我收到错误: 在“AppModule”的模板编译期间出现错误错误在装饰器中不支持函数调用,但调用了“
问题类型:错误/问题

描述

我正在使用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,输入
npm安装
ng build –prod.

预期的行为

想用AOT构建没有错误(我需要它与Angular Universal兼容)
版本信息

ng-packagr:2.4.1
@ angular / *:5.2.9
打字稿:2.5.3
rxjs:5.5.6
节点:8.1.0
npm / yarn:npm:5.6.0

文件:

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

如果缺少一些必要的信息,请告诉我,我会提供.

谢谢,
Bloodcast69

解决方法

这是AOT的一个问题:forRoot函数需要在编译时执行.在更新版本的Angular上它应该按原样运行,否则你可能会运气玩tsconfig.app.json.检查此相关问题: Angular 6 Prod Function calls are not supported in decorators but ‘..Module’ was called

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读