【问题标题】:Please add a @Pipe/@Directive/@Component annotation IONIC 3请添加@Pipe/@Directive/@Component 注解 IONIC 3
【发布时间】:2019-04-24 16:59:00
【问题描述】:

这在作为开发运行时可以正常工作,但是当您将命令运行到生产时出现以下错误:

工作:

ionic cordova run android

不工作:

ionic cordova run android --prod --release

错误:

    [03:34:41]  typescript error
                Unexpected module 'TranslateModule in C:/Users/tm_ma/Doc/PROJECT/node_modules/@ngx-translate/core/core.d.ts' declared by the module 'EmentaPageModule in
                C:/Users/tm_ma/Doc/PROJECT/src/pages/ementa/ementa.module.ts'. Please add a
                @Pipe/@Directive/@Component annotation.
  [03:34:41]  ionic-app-script task: "build"
  [03:34:41]  Error: The Angular AoT build failed. See the issues above
    Error: The Angular AoT build failed. See the issues above

元素模块:

import { NgModule, Component } from '@angular/core'; 
import { IonicPageModule } from 'ionic-angular'; 
import { EmentaPage } from './ementa'; import { TranslateModule } from '@ngx-translate/core';


@NgModule({  
   declarations: [
    EmentaPage,
    TranslateModule
       ],   imports: [
    IonicPageModule.forChild(EmentaPage),
    TranslateModule
       ], }) export class EmentaPageModule {}

应用模块:

export function createTranslateLoader(http: HttpClient) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}

@NgModule({
  declarations: [
   ...
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    IonicModule.forRoot(MyApp),
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [HttpClient]
      }
    })

  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
   ...
  ],
  providers: [

  ]
})
export class AppModule {}

版本:

"@ngx-translate/core": "^9.1.1",
"@ngx-translate/http-loader": "^4.0.0",   
"angularfire2": "^5.0.0-rc.11",   
"@angular/animations": "5.2.11",    
"@angular/common": "5.2.11",    
"@angular/compiler": "5.2.11",   
"@angular/compiler-cli": "5.2.11",    
"@angular/core": "5.2.11",    
"@angular/forms": "5.2.11",   
"@angular/http": "5.2.11",

【问题讨论】:

  • TranslateModule 不应该在声明数组中。从那里删除后尝试
  • @SurajRao 感谢您的回答,我从 declrations 数组中删除了,知道给我这个 -> [14:20:09] 打字稿错误找不到管道“翻译”(“{{[ERROR ->]'INFOALUNO.headerMsg' | translate}}标题> ")

标签: angular typescript ionic-framework ionic3


【解决方案1】:

Angular5 应该使用 core 8.x - 9.x 和 loader 1.x - 2.x Angular4.3 应该使用 core 7.x 或更低版本和 loader 1.x - 2.x

详情https://github.com/ngx-translate/core

我的应用使用了 ionic4 (angular6),ngx-translate 对我来说没问题(核心 10.x 和 loader 3.x)

【讨论】:

    猜你喜欢
    • 2018-03-14
    • 2019-01-27
    • 1970-01-01
    • 2021-08-15
    • 1970-01-01
    • 2017-12-23
    • 1970-01-01
    • 1970-01-01
    • 2017-12-15
    相关资源
    最近更新 更多