Please suggest a better title if you can think of one
We have a multi-module enterprise application that is written in Angular 2
To handle multi-customer use of our system we have an override strategy for images and such. Basically a map of strings to file locations. To switch which assets get overridden we pass the map to override the existing map into the .forAssets() method below. This pattern was taken from the Angular 2 RouterModule source code.
This issue is when AOT compiling we get the error
Error: Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol MainModule in /Users/--/--/my-module/index.ts, resolving symbol MainModule in /Users/--/--/common-module/index.ts
Top Level Module
@NgModule({
imports: [
AssetsModule.forAssets(),
SomeModule
]
})
export class MainModule{
public ngDoBootstrap(ref: ApplicationRef){
ref.bootstrap(StartupComponent);
}
}
platformBrowser().bootstrapModuleFactory(MainModuleNgFactory);
Some Module
@NgModule({
declarations: [
...
],
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
AssetsModule,
RouterModule.forRoot(SOME_ROUTES, {useHash: true})
],
providers: [
...
],
schemas:[
NO_ERRORS_SCHEMA
],
bootstrap: [StartupComponent]
})
export class SomeModule {}
Copying the Angular 2 RouterModule.forChild() pattern that they used for overrides. I have created a similar override structure for our AssetsModule
AssetsModule
@NgModule({
declarations: [
ImgDirective
],
providers: [
AssetService
]
})
export class AssetsModule{
public static forAssets(...overrides: any[]): ModuleWithProviders{
const providers = [{provide: ASSETS, multi: true, useValue: DefaultAssets}];
providers.concat(overrides.map(override => {
return {provide: ASSETS, multi: true, useValue: override};
}));
return {
ngModule: AssetsModule,
providers: providers
};
}
}
ASSETS is an OpaqueToken
This error, as unhelpful as it is, only occurs when the line AssetsModule.forAssets() is present in the top level module. If I comment it out or remove it the compilation succeeds.
forAssetscontents to bare minimum to see what will happen? Notice thatforChildyou're referring to calls onlyprovideRoutes, which is named exported function (as the error suggests), whileforAssetshas pretty much inside, including an anonymous arrow.