离子在构建时给出打字稿错误

开发商

您好,我正在尝试使用命令构建用于生产的 android 应用程序 ionic cordova build android --prod

问题是,在运行此代码后,它给了我以下打字稿错误。

    typescript error
    Type ContactPage in C:/Users/Akshay S. Shrivastav/Desktop/vidyotan_2k18/src/pages/contact/contact.ts is part
    of the declarations of 2 modules: AppModule in C:/Users/Akshay S.
    Shrivastav/Desktop/vidyotan_2k18/src/app/app.module.ts and ContactPageModule in C:/Users/Akshay S.
    Shrivastav/Desktop/vidyotan_2k18/src/pages/contact/contact.module.ts! Please consider moving ContactPage in
    C:/Users/Akshay S. Shrivastav/Desktop/vidyotan_2k18/src/pages/contact/contact.ts to a higher module that
    imports AppModule in C:/Users/Akshay S. Shrivastav/Desktop/vidyotan_2k18/src/app/app.module.ts and
    ContactPageModule in C:/Users/Akshay S.
    Shrivastav/Desktop/vidyotan_2k18/src/pages/contact/contact.module.ts. You can also create a new NgModule
    that exports and includes ContactPage in C:/Users/Akshay S.
    Shrivastav/Desktop/vidyotan_2k18/src/pages/contact/contact.ts then import that NgModule in AppModule in
    C:/Users/Akshay S. Shrivastav/Desktop/vidyotan_2k18/src/app/app.module.ts and ContactPageModule in
    C:/Users/Akshay S. Shrivastav/Desktop/vidyotan_2k18/src/pages/contact/contact.module.ts.

    Error: The Angular AoT build failed. See the issues above
        at C:\Users\Akshay S. Shrivastav\Desktop\vidyotan_2k18\node_modules\@ionic\app-scripts\dist\aot\aot-compiler.js:237:55
        at step (C:\Users\Akshay S. Shrivastav\Desktop\vidyotan_2k18\node_modules\@ionic\app-scripts\dist\aot\aot-compiler.js:32:23)
        at Object.next (C:\Users\Akshay S. Shrivastav\Desktop\vidyotan_2k18\node_modules\@ionic\app-scripts\dist\aot\aot-compiler.js:13:53)
        at fulfilled (C:\Users\Akshay S. Shrivastav\Desktop\vidyotan_2k18\node_modules\@ionic\app-scripts\dist\aot\aot-compiler.js:4:58)

这是我的 app.component.ts

import { Component, ViewChild } from '@angular/core';
import { Nav, Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

import { HomePage } from '../pages/home/home';
import { EventsPage } from '../pages/events/events';
import { WorkshopsPage } from '../pages/workshops/workshops';
import { TeamPage } from '../pages/team/team';
import { ContactPage } from '../pages/contact/contact';
import { DeveloperPage } from '../pages/developer/developer';
import { WildcardPage } from '../pages/wildcard/wildcard';
// import { DetailsPage } from '../pages/details/details';

@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  @ViewChild(Nav) nav: Nav;

rootPage: any = HomePage;

pages: Array<{title: string, component: any}>;

constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen) {
  this.initializeApp();

  //menu navigators
  this.pages = [
    { title: 'Home', component: HomePage },
    { title: 'Events', component: EventsPage },
    { title: 'Wildcard Entries', component: WildcardPage },
    { title: 'Workshops', component: WorkshopsPage },
    { title: 'Vidyotan Team', component: TeamPage },
    { title: 'Contact', component: ContactPage },
    { title: 'App Developer', component: DeveloperPage },
  ];

}

initializeApp() {
  this.platform.ready().then(() => {
    // Okay, so the platform is ready and our plugins are available.
    // Here you can do any higher level native things you might need.
    // this.statusBar.styleDefault();
    this.statusBar.backgroundColorByHexString("#337ab7");
    this.splashScreen.hide();
  });
}

openPage(page) {
  // Reset the content nav to have just this page
  // we wouldn't want the back button to show in this scenario
  this.nav.setRoot(page.component);
}
}

这是我的 app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { EventsPage } from '../pages/events/events';
import { WorkshopsPage } from '../pages/workshops/workshops';
import { TeamPage } from '../pages/team/team';
import { ContactPage } from '../pages/contact/contact';
import { DeveloperPage } from '../pages/developer/developer';
import { DetailsPage } from '../pages/details/details';
import { WildcardPage } from '../pages/wildcard/wildcard';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    EventsPage,
    WorkshopsPage,
    TeamPage,
    ContactPage,
    DeveloperPage,
    DetailsPage,
    WildcardPage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    EventsPage,
    WorkshopsPage,
    TeamPage,
    ContactPage,
    DeveloperPage,
    DetailsPage,
    WildcardPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

这是我的 contact.ts

import { Component } from '@angular/core';
    import { IonicPage, NavController, NavParams } from 'ionic-angular';

    // import { Contact1Page } from '../contact/contact';

    @IonicPage()
    @Component({
      selector: 'page-contact',
      templateUrl: 'contact.html',
    })
    export class ContactPage {

      constructor(public navCtrl: NavController, public navParams: NavParams) {
      }

      ionViewDidLoad() {
        console.log('ionViewDidLoad ContactPage');
      }

    }

这是我的 contact.module.ts

import { NgModule } from '@angular/core';
    import { IonicPageModule } from 'ionic-angular';
    import { ContactPage } from './contact';

    @NgModule({
      declarations: [
        ContactPage,
      ],
      imports: [
        IonicPageModule.forChild(ContactPage),
      ],
    })
    export class ContactPageModule {}

可能是什么问题我无法得到它。根据我的说法,UI 已经完成了所有工作,我还搜索了各种论坛,但在为生产环境构建应用程序时仍然出现相同的错误。

请帮助,提前致谢。

马赫什·贾达夫

我多次遇到这个问题,因为 ionic 说特定页面是两个声明的一部分,一个是我们的主要应用程序组件声明,第二个是单个组件模块。所以基本上从单个 component.module.ts 文件中删除它对我有用所以尝试从你的 contact.module.ts 文件中删除页面声明

@NgModule({
  declarations : [
                     //keep this empty 
  ],
  imports : [
   .... 
  ]

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

构建nodeJs时出现打字稿错误

来自分类Dev

打字稿错误离子 3

来自分类Dev

打字稿错误';' 预期的。离子 2

来自分类Dev

为什么在尝试结帐时create-react-app会给出打字稿错误(尽管没有打字稿文件)?

来自分类Dev

构建时出现离子错误

来自分类Dev

投放时出现打字稿错误

来自分类Dev

为什么打字稿在类型联合上给出类型错误?

来自分类Dev

json 2 打字稿映射给出了类型错误

来自分类Dev

打字稿构建失败

来自分类Dev

成功构建,打字稿键入文件中出现许多错误

来自分类Dev

打字稿在构建时保留子目录

来自分类Dev

在为hawtio进行构建时遇到问题“错误代码:EPERM”,其中包括打字稿和Angular文件

来自分类Dev

反应 + 打字稿错误

来自分类Dev

画布打字稿错误

来自分类Dev

离子打字稿错误(“主页”类型上不存在属性“导航”)

来自分类Dev

类型错误:无法读取 null 的属性“map”。离子 3 打字稿

来自分类Dev

打字稿1.3有时会给出错误的类型不匹配错误

来自分类Dev

将声明设置为TRUE时出现打字稿错误

来自分类Dev

订阅rxjs主题时,打字稿中的类型错误?

来自分类Dev

当值可以为function或null时,打字稿错误

来自分类Dev

使用类似树的指针时打字稿记录错误

来自分类Dev

错误:TS2345:使用打字稿进行编译时

来自分类Dev

函数返回类型为 Promise<{ then: () => void }> 时打字稿错误

来自分类Dev

返回 subject.asObservable() 时出现打字稿错误

来自分类Dev

离子构建Android错误

来自分类Dev

错误离子构建Android

来自分类Dev

离子构建Android错误

来自分类Dev

离子 Cordova 构建错误

来自分类Dev

如何使用打字稿禁用离子选择。离子2

Related 相关文章

热门标签

归档