I am currently making a custom angular library that is dependent on the hosts environment. Ideally, I would just like to pass a couple environment variables in the forRoot method of my module for a service to use depending what app is using it and what environment they are in. However I am getting an error when compiling with angular-cli and just passing in variables from my environment.ts in app.module.ts.
ERROR in 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 (position 19:24 in the original .ts file), resolving symbol environment in /Users/griffin/DCP/customer-dashboard/src/environments/environment.ts, resolving symbol AppModule in /Users/griffin/DCP/customer-dashboard/src/app/app.module.ts, resolving symbol AppModule in /Users/griffin/DCP/customer-
The custom module's index is currently setup like this:
@NgModule({
declarations: [],
exports: [],
providers: [
AuthService
],
imports: [
HttpModule,
BrowserModule
]
})
export class CommonAuthModule {
static forRoot(config: AuthServiceConfig): ModuleWithProviders {
return {
ngModule: CommonAuthModule,
providers: [
{provide: AuthServiceConfig, useValue: config }
]
};
}
And in a Angular project I am importing like this:
import { CommonAuthModule } from '@dcp/common-auth';
import { environment } from '../environments/environment';
@NgModule({
declarations: [
AppComponent
],
imports: [
CommonAuthModule.forRoot(environment.authConfig) // Import here
...
})
export class AppModule { }
environment.authConfig is simple object
authConfig: {
authenticationUrl: 'https://streamworks.auth0.com/login?client=',
clientId: 'f98h3f3fdsousfoihohfjwe0',
auth0Domain: 'streamworks.auth0.com'
}
And AuthServiceConfig is a simple class
export class AuthServiceConfig {
clientId: string = ''
auth0Domain: string = '';
authenticationUrl: string = '';
}
I have seen similar issues like this post. Is this related to AoT compiling?. I tried building the project by bypassing AoT but I still get the same error.