在我的库中执行'ng build'时,出现以下错误。
我目前正在使用Angular 6,但我认为这个错误与版本无关。
/home/rafaelvicio/desenv/my-lib/arquitetura-web/projects/pf-siseg/src/lib/keycloak-service/keycloak.service.ts:13:1: 在导出符号“KeycloakService”生成的元数据中遇到错误:
/home/rafaelvicio/desenv/my-lib/arquitetura-web/projects/pf-siseg/src/lib/keycloak-service/keycloak.service.ts:18:12: 收集到的元数据包含一个运行时将报告的错误:因为模板编译器需要此变量的值,所以只能引用已初始化的变量和常量。
{"__symbolic":"error","message":"Variable not initialized","line":17,"character":11} Error: /home/rafaelvicio/desenv/my-lib/arquitetura-web/projects/pf-siseg/src/lib/keycloak-service/keycloak.service.ts:13:1: 在导出符号“KeycloakService”生成的元数据中遇到错误:
/home/rafaelvicio/desenv/my-lib/arquitetura-web/projects/pf-siseg/src/lib/keycloak-service/keycloak.service.ts:18:12: 收集到的元数据包含一个运行时将报告的错误:因为模板编译器需要此变量的值,所以只能引用已初始化的变量和常量。
{"__symbolic":"error","message":"Variable not initialized","line":17,"character":11} at /home/rafaelvicio/desenv/my-lib/arquitetura-web/node_modules/@angular/compiler-cli/src/metadata/collector.js:707:31 at Array.forEach () at validateMetadata (/home/rafaelvicio/desenv/my-lib/arquitetura-web/node_modules/@angular/compiler-cli/src/metadata/collector.js:695:46) at MetadataCollector.getMetadata (/home/rafaelvicio/desenv/my-lib/arquitetura-web/node_modules/@angular/compiler-cli/src/metadata/collector.js:550:21) at MetadataCache.getMetadata (/home/rafaelvicio/desenv/my-lib/arquitetura-web/node_modules/@angular/compiler-cli/src/transformers/metadata_cache.js:86:41) at Object.getSourceFileMetadata (/home/rafaelvicio/desenv/my-lib/arquitetura-web/node_modules/@angular/compiler-cli/src/transformers/compiler_host.js:112:56) at Object.readMetadata (/home/rafaelvicio/desenv/my-lib/arquitetura-web/node_modules/@angular/compiler-cli/src/transformers/metadata_reader.js:46:37) at TsCompilerAotCompilerTypeCheckHostAdapter.getMetadataFor (/home/rafaelvicio/desenv/my-lib/arquitetura-web/node_modules/@angular/compiler-cli/src/transformers/compiler_host.js:464:38) at StaticSymbolResolver.getModuleMetadata (/home/rafaelvicio/desenv/my-lib/arquitetura-web/node_modules/@angular/compiler/src/aot/static_symbol_resolver.js:480:49) at StaticSymbolResolver._createSymbolsOf (/home/rafaelvicio/desenv/my-lib/arquitetura-web/node_modules/@angular/compiler/src/aot/static_symbol_resolver.js:268:33)
keycloak.service.ts:
import { Injectable } from '@angular/core';
import { KeycloakLoginOptions } from './keycloak.d';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import * as Keycloak from './keycloak';
export type KeycloakClient = Keycloak.KeycloakInstance;
type InitOptions = Keycloak.KeycloakInitOptions;
@Injectable()
export class KeycloakService {
constructor(private http: HttpClient) { }
static keycloakAuth: KeycloakClient;
.... More code here
static
方法有关。添加// @dynamic
可以解决它。 - dude