【问题标题】:Ionic 2 RC0 And Angular 2 latest Error on Build android (ngc: Error: Error encountered resolving symbol values statically)Ionic 2 RC0 和 Angular 2 最新的 Build android 错误(ngc:错误:遇到静态解析符号值的错误)
【发布时间】:2017-02-21 09:53:33
【问题描述】:

使用ionic build android 命令构建android 时出现错误

ngc:错误:静态解析符号值时遇到错误。对本地(非导出)符号“字典”的引用。考虑导出符号(原始 .ts 文件中的位置 14:8),解析符号 TRANSLATION_PROVIDERS

translation.ts 文件中的代码

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},
];

我的 app.module.ts 代码

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 {}

关于这个问题的任何建议,顺便说一下,当我使用 ionic serve 命令时,我的项目通过转换 100% 工作

【问题讨论】:

  • 你能创建一个最小的 git repo 吗?

标签: android angular typescript compilation ionic2


【解决方案1】:

我找到了解决方法。

您不必导出字典对象,只需将键更改为静态值。

这对我有用:

// 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】:

    是的,正如@welefish 在他的回答中所说,无需导出您的字典对象,您只需将键更改为静态值。

    PS:- 另一种方法(作为答案发布,因为@welefish 方法不适合我)

    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】:

      好吧,按照编译器说的做 :)。导出您的字典:

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

      【讨论】:

      • 首先感谢您的回答@PierreDuc,出现错误ngc: Error: Error encountered resolving symbol values statically. Expression form not supported (position 15:5 in the original .ts file), resolving symbol dictionary in D:/Mle/.tmp/app/translate/translations.ts, resolving symbol TRANSLATION_PROVIDERS in D:/Mle/.tmp/app/translate/translations.ts, resolving symbol AppModule in D:/Mle/.tmp/app/app.module.ts, resolving symbol AppModule in D:/Mle/.tmp/app/app.module.ts
      • @OscarBout 你有什么问题?
      • 和@PAncho一模一样:我把原来的:scotch.io/tutorials/…改成了你的解决方案,得到了同样的错误
      【解决方案4】:

      声明 [LANG_EN_NAME] 的类型:

      export const LANG_EN_NAME : string = 'en';
      

      为我工作。

      【讨论】:

        猜你喜欢
        • 2023-03-12
        • 2017-02-13
        • 1970-01-01
        • 2017-08-02
        • 2017-09-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-03
        相关资源
        最近更新 更多