3

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?

Glenn Utter
  • 2,313
  • 7
  • 32
  • 44
  • I've came across the same problem. I've tried replacing useFactory: with useFactory: with no luck. The issue might be that ng2-translate's devs did not push *.metadata.json files among their .d.ts and .js files. PS: Don't think that the .forRoot() method calls are the issue, ngc can resolve those well. – Alin Florin Sep 20 '16 at 11:20

2 Answers2

4

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]
    })
],
Isaac
  • 2,173
  • 1
  • 13
  • 15
0

you have to update ng2-translate to >5.0.0 first of all. I had the same issue on version ~2.5.0 and exported function did not help.

So your steps:

  1. Update version >5.0.0
  2. Export function as mentioned by Isaac:

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

@NgModule({ imports: [ CommonModule, TranslateModule.forRoot({ provide: TranslateLoader, useFactory: translateStaticLoaderFactory, deps: [Http] }) ],

koorosh
  • 414
  • 4
  • 7