为什么Android的发布版本会在所有其他版本运行时失败

时间:2018-02-09 23:20:09

标签: ionic-framework ionic3

重现的步骤:

$ ionic --version
3.19.1

$ cordova --version
8.0.0

按照离子文档写信:

ionic start showbug blank
cd showbug
ionic generate component gaga

然后将GagaComponent添加到app.modules.ts

的声明中
...
import { GagaComponent } from '../components/gaga/gaga';

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    GagaComponent
  ],
...

现在可以观察到这个问题,但只有为Android构建发布

  • ionic serve正常工作
  • ionic cordova build android按预期工作
  • ionic cordova build android --release --prod收益率 typescript error Type GagaComponent in PATH_TO_APP/showbug/src/components/gaga/gaga.ts is part of the declarations of 2 modules: AppModule in PATH_TO_APP/showbug/src/app/app.module.ts and ComponentsModule in PATH_TO_APP/showbug/src/components/components.module.ts! Please consider moving GagaComponent in PATH_TO_APP/showbug/src/components/gaga/gaga.ts to a higher module that imports AppModule in PATH_TO_APP/showbug/src/app/app.module.ts and ComponentsModule in PATH_TO_APP/showbug/src/components/components.module.ts. You can also create a new NgModule that exports and includes GagaComponent in PATH_TO_APP/showbug/src/components/gaga/gaga.ts then import that NgModule in AppModule in PATH_TO_APP/showbug/src/app/app.module.ts and ComponentsModule in PATH_TO_APP/showbug/src/components/components.module.ts.

2 个答案:

答案 0 :(得分:0)

在Ionic 3中,当您生成组件时,它会创建与组件相关的ts和scss页面以及component.module.ts

该组件将在component.module.ts中声明。

@NgModule({
  declarations: [
    GagaComponent,
    //any other generated components
  ],
  imports: [
    IonicModule
  ],
  exports: [
     GagaComponent,
    //any other generated components
  ]
})

您需要将此模块导入app.module.ts

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    ComponentsModule,//here
  ],

或者您可以在任何需要使用它的页面模块中设置导入

答案 1 :(得分:0)

GagaComponent

declarations移除component.module.ts