Ionic 2 RC0 And Angular 2 latest Error on Build android (ngc: Error: Error encountered resolving symbol values statically)

折月煮酒 提交于 2019-12-07 17:00:48

问题


Error Appear when i build android using ionic build android command

ngc: Error: Error encountered resolving symbol values statically. Reference to a local (non-exported) symbol 'dictionary'. Consider exporting the symbol (position 14:8 in the original .ts file), resolving symbol TRANSLATION_PROVIDERS

My code in translation.ts file

export const TRANSLATIONS = new OpaqueToken('translations');
// all traslations
 const dictionary : any = {
    [LANG_EN_NAME]: LANG_EN_TRANS,
    [LANG_AR_NAME]: LANG_AR_TRANS,
    [LANG_FR_NAME]: LANG_FR_TRANS
};
// providers
export const TRANSLATION_PROVIDERS : any = [
    { provide: TRANSLATIONS, useValue: dictionary},
];

My app.module.ts code

import {TRANSLATION_PROVIDERS,TranslatePipe,TranslateService} from './translate';

@NgModule({
  declarations: [
    MyApp,
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,

  ],
  providers: [TRANSLATION_PROVIDERS,TranslateService ]
})
export class AppModule {}

any suggestions about this issue, by the way when im using ionic serve command my project work 100% with transaltion


回答1:


I found a workaround for that.

you don't have to export your dictionary object, just change the keys to static values.

This worked for me:

// all translations
const dictionary = {
  "en": LANG_EN_TRANS,
  "ar": LANG_AR_TRANS,
  "fr": LANG_FR_TRANS
};
// providers
export const TRANSLATION_PROVIDERS = [
  { provide: TRANSLATIONS, useValue: dictionary },
];



回答2:


Yes exactly as said by @welefish in his answer, no need to export your dictionary object, you just have to change to keys to static value.

PS:- another method (Posting as answer because @welefish method is not working for me)

let en = LANG_EN_NAME;
let er = LANG_AR_NAME;
let fr = LANG_FR_NAME;

const dictionary : any = {
    en: LANG_EN_TRANS,
    er: LANG_AR_TRANS,
    fr: LANG_FR_TRANS
};

// providers
export const TRANSLATION_PROVIDERS = [
  { provide: TRANSLATIONS, useValue: dictionary },
];



回答3:


Well, do what the compiler says :). Export your dictionary:

export const dictionary : any = {
    [LANG_EN_NAME]: LANG_EN_TRANS,
    [LANG_AR_NAME]: LANG_AR_TRANS,
    [LANG_FR_NAME]: LANG_FR_TRANS
};



回答4:


Declare the type of [LANG_EN_NAME]:

export const LANG_EN_NAME : string = 'en';

Worked for me.



来源:https://stackoverflow.com/questions/40001256/ionic-2-rc0-and-angular-2-latest-error-on-build-android-ngc-error-error-encou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!