Forgive me, but I am on a difficult project and don't understand much about it. I have done some research and it has not helped resolve. Given this class:
import { Injector, Type, InjectionToken, AbstractType, InjectFlags } from '@angular/core'; let _appInjector: Injector; // The AppInjector would normally consist only of the setAppInjector function and the exportet variable: // export let AppInjector: Injector; // Because Karma/Jasmine unit tests have problems accessing exportet variables, the AppInjector // implementation is changed into a class with a static "get" method. In that way, unit tests work and // existing implementations can stay unchanged. export class AppInjector { static get<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T { return _appInjector.get(token, notFoundValue, flags); } } export function setAppInjector(injector: Injector): void { if (_appInjector === undefined) { _appInjector = injector; } } export function appInjector<T>( token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue?: T, flags?: InjectFlags ) { return function (target: any, key: string | symbol) { const getter = function () { const injectable = AppInjector.get(token, notFoundValue, flags); return injectable; }; const setter = (value: any) => { console.error('Not allowed to set a decorated app-injector.'); }; Object.defineProperty(target, key, { get: getter, set: setter, enumerable: true, configurable: true }); }; }
I get the following error when building with --prod:
Building entry point '@dn/vcp-core-lib' ------------------------------------------------------------------------------ × Compiling TypeScript sources through NGC ERROR: C:/repo/Diebold/bay-bridge/libs/vcp-core-lib/src/lib/common/app-injector.ts:11:1: Error encountered in metadata generated for exported symbol 'AppInjector': C:/repo/Diebold/bay-bridge/libs/vcp-core-lib/src/lib/common/app-injector.ts:3:5: Metadata collected contains an error that will be reported at runtime: Reference to a local (non-exported) symbol '_appInjector'. Consider exporting the symbol. {"__symbolic":"error","message":"Reference to a local symbol","line":2,"character":4,"context":{"name":"_appInjector"}} C:/repo/Diebold/bay-bridge/libs/vcp-core-lib/src/lib/common/app-injector.ts:11:1: Error encountered in metadata generated for exported symbol 'AppInjector': C:/repo/Diebold/bay-bridge/libs/vcp-core-lib/src/lib/common/app-injector.ts:3:5: Metadata collected contains an error that will be reported at runtime: Reference to a local (non-exported) symbol '_appInjector'. Consider exporting the symbol. {"__symbolic":"error","message":"Reference to a local symbol","line":2,"character":4,"context":{"name":"_appInjector"}}
I tried sinmply exporting _appInjector, but that only leads to another error. It is expecting a value on the initalization of _appInjector. I tried setting its' value to new AppInjector (from angular/core) but that is an abstract class that can't be instantiated. Any ideas or requests for more information are welcome, but I really don't understand what this class is even doing.
https://stackoverflow.com/questions/67236676/how-can-i-fix-this-build-error-when-using-the-prod-flag-for-an-angular-applib April 24, 2021 at 04:49AM
没有评论:
发表评论