重现的步骤:
$ 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.
答案 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