Home > Software design >  error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors AppRoutingModule
error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors AppRoutingModule

Time:01-10

When I make: ionic cap build android --prod --release , I have this error :

Error: src/app/app-routing.module.ts:60:14 - error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors

export class AppRoutingModule {}

Error

I don't have this error when I just do : ionic cap build android. I try different proposition on forums but no one work

app-routing.module.ts :

    import { NgModule } from '@angular/core';
    import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
    import { TranslateService } from '@ngx-translate/core';

    const routes: Routes = [
    {
        path: 'HomePage',
        loadChildren: () => import('./pages/home/home.module').then(m => m.HomePageModule)
    },
    {
        path: 'IntroPage',
        loadChildren: () => import('./pages/intro/intro.module').then(m => m.IntroPageModule)
    },
    {
        path: 'HowPage',
        loadChildren: () => import('./pages/how/how.module').then(m => m.HowPageModule)
    },
    {
        path: 'AboutPage',
        loadChildren: () => import('./pages/about/about.module').then(m => m.AboutPageModule)
    },
    {
        path: 'SettingsPage',
        loadChildren: () => import('./pages/settings/settings.module').then(m => m.SettingsPageModule)
    },
    {
        path: 'ModalPage',
        loadChildren: () => import('./pages/modal/modal.module').then(m => m.ModalPageModule)
    },
    {
        path: '',
        redirectTo: 'HomePage',
        pathMatch: 'full'
    },
    ];

    @NgModule({
        imports: [
            RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
      ],
        exports: [RouterModule, TranslateService]
    })
    export class AppRoutingModule {}

app.module.ts :

    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { RouteReuseStrategy } from '@angular/router';
    import { HttpClientModule, HttpClient } from '@angular/common/http';

    import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
    import { IonicStorageModule } from '@ionic/storage-angular';

    import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
    import { TranslateHttpLoader } from '@ngx-translate/http-loader';

    import { AppComponent } from './app.component';
    import { AppRoutingModule } from './app-routing.module';

    import { GlobalProvider } from './providers/global/global';

    import { CMHPlugin } from '@ionic-native/cmh-plugin/ngx';

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

    @NgModule({
        declarations: [AppComponent],
        imports: [
            HttpClientModule,
            BrowserModule,
            IonicModule.forRoot(),
            IonicStorageModule.forRoot(),
            AppRoutingModule,
            TranslateModule.forRoot({
                loader: {
                    provide: TranslateLoader,
                    useFactory: (createTranslateLoader),
                    deps: [HttpClient]
                },
                defaultLanguage: 'en',
            })
        ],
        providers: [GlobalProvider, CMHPlugin, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
        bootstrap: [AppComponent]
    })
    export class AppModule {}

I use Ionic 6 and Angular 13. I can give more information/code if you need.

CodePudding user response:

I remove TranslateService in export [] in app-routing.module.ts and it' works !

  •  Tags:  
  • Related