Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 RC6: cli-compiler says "function calls are not supported"

When trying to compile my RC6 app using the following command:

ngc -p C:\Path\To\Project

(I am placed inside C:\Path\To\Project\node_modules\.bin when I'm running the command)

I get the following 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 20:25 in the original .ts file), resolving symbol CoreModule in C:/Path/To/Project/app/modules/core/core.module.ts

This is what it complains about:

@NgModule({
imports: [
    CommonModule,
    TranslateModule.forRoot({ 
        provide: TranslateLoader,
        useFactory: (http: Http) => new TranslateStaticLoader(http, 'app/languages', '.json'),
        deps: [Http]
    })
],

If I remove TranslateModule.forRoot... the error disappears.

How do I replace this with an exported function as the error implies?

like image 298
Glenn Utter Avatar asked Aug 24 '26 22:08

Glenn Utter


1 Answers

I'm having some luck doing this:

export function translateStaticLoaderFactory(http: Http) {
  return new TranslateStaticLoader(http, 'app/languages', '.json');
}

@NgModule({
imports: [
    CommonModule,
    TranslateModule.forRoot({ 
        provide: TranslateLoader,
        useFactory: translateStaticLoaderFactory,
        deps: [Http]
    })
],
like image 171
Isaac Avatar answered Aug 28 '26 08:08

Isaac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!