Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: module 'AppRoutingModule' is exported recursively by the module 'AppRoutingModule'

I am building a angular application, everything was working fine till I imported and implemented the "Routing Module"

Error Message

enter image description here

I have gone through and don't think the following are possible problems:

  • Syntax errors, like multiple commas and such
  • Recursive calls

Code for Router Module:

import { NgModule } from '@angular/core';
import { Routes , RouterModule } from '@angular/router';
import { RecipesComponent } from './recipes/recipes.component';
import { ShoppingListComponent } from './shopping-list/shopping-list.component';

const appRoutes: Routes = [
	{path: 'recipes', component: RecipesComponent},
	{path: 'shopping-list', component: ShoppingListComponent},
  	{ path: '', redirectTo: 'recipes', pathMatch: 'full'},
  	{ path: '**', redirectTo: '/not-found'},
]

@NgModule({
	imports: [
		RouterModule.forRoot(appRoutes),
	],
	exports: [AppRoutingModule]
})

export class AppRoutingModule{

}

Code for Root Component:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { RecipesComponent } from './recipes/recipes.component';
import { RecipeListComponent } from './recipes/recipe-list/recipe-list.component';
import { RecipeDetailComponent } from './recipes/recipe-detail/recipe-detail.component';
import { RecipeItemComponent } from './recipes/recipe-list/recipe-item/recipe-item.component';
import { ShoppingListComponent } from './shopping-list/shopping-list.component';
import { ShoppingEditComponent } from './shopping-list/shopping-edit/shopping-edit.component';
import { DropdownDirective } from './shared/dropdown.directive';
import { ShoppingListService } from './shopping-list/shopping-list.service';
import { AppRoutingModule } from './app-routing.module';

@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    RecipesComponent,
    RecipeListComponent,
    RecipeDetailComponent,
    RecipeItemComponent,
    ShoppingListComponent,
    ShoppingEditComponent,
    DropdownDirective
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    AppRoutingModule
  ],
  providers: [ShoppingListService],
  bootstrap: [AppComponent]
})
export class AppModule { }
like image 606
M Masood Avatar asked Jan 26 '23 17:01

M Masood


2 Answers

You are exporting the wrong module. Change exports: [AppRoutingModule] to exports: [RouterModule].

@NgModule({
    imports: [
        RouterModule.forRoot(appRoutes),
    ],
    exports: [RouterModule]
})
export class AppRoutingModule {
}
like image 158
Reactgular Avatar answered Feb 05 '23 14:02

Reactgular


Try to change:

exports: [AppRoutingModule]

to:

exports: [
    RouterModule
  ]
like image 44
Hien Nguyen Avatar answered Feb 05 '23 14:02

Hien Nguyen