2

I just migrated my project under angular-cli and I'm getting this error when I start it:

ERROR in 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 63:45 in the original .ts file), resolving symbol AppModule in C:/Data/Private/Innovation/EV/ev-dashboard/src/app/app.module.ts

Which corresponds to the APP_INITIALIZER below in app.module.ts:

...
providers: [ // expose our Services and Providers into Angular's dependency injection
    APP_PROVIDERS,
    ConfigService,
    { provide: APP_INITIALIZER, useFactory: (config: ConfigService) => () => config.load(), deps: [ConfigService], multi: true }
...

What is funny is that when I comment this line, it starts well and uncomment it afterward which triggers a compilation without error this time!!!

Do you have an idea?

Thanks, Serge.

LucasBrazi06
  • 117
  • 13

1 Answers1

1

You need to extract function like:

export function configFactory(config: ConfigService) {
  return () => config.load()
}

...
providers: [{ 
  provide: APP_INITIALIZER, 
  useFactory: configFactory, 
  deps: [ConfigService], 
  multi: true 
}

See also

Community
  • 1
  • 1
yurzui
  • 205,937
  • 32
  • 433
  • 399