3

My Angular project folder structure is

+-- app.module.ts
+-- app-routing.ts
+-- app.component.ts
+-- product/
|   +-- product.module.ts
|   +-- product-routing.ts
|   +-- product-detail/
|   |   +--product-detail.component.ts
|   |   +--product-detail.component.html

In my app-routing.ts

{path:'products',loadChildren:'app/product/product.module#ProductModule'}

In my product-routing.ts

{ path: 'detail', component: ProductDetailComponent }

When I load the url - page/product/detail , I get the following error

ERROR Error: Uncaught (in promise): Error: Cannot find module "app/product/product.module". Error: Cannot find module "app/product/product.module".

Steps tried
tried changing 'app/product/product.module#ProductModule' to './product/product.module#ProductModule'. not solved.

Where I have went wrong? Any help is appreciated.

3
  • restart ng serve Commented Jul 4, 2018 at 10:31
  • 1
    'product' or 'products'? Subfolder includes 's' at the end and all configs/routings as well? Commented Jul 4, 2018 at 10:34
  • Possible duplicate of Angular2 lazy loading module error 'cannot find module' Commented Jul 4, 2018 at 10:34

3 Answers 3

1

You can try loadChildren for lazy module loading

I have create a demo on Stackblitz

{path:'products',loadChildren: './product/product.module#ProductsModule''}
Sign up to request clarification or add additional context in comments.

4 Comments

Excellent solution :)
Yes it worked, it would be great if you explain why loadChildren: () =>ProductsModule works but not loadChildren:'app/products/products.module#ProductModule'
It is working because it is not lazy loaded anymore!
you can do something like this as well : loadChildren:'./java/java.module#JavaModule'
1

That can be solved by removing your typo mistake. You declared Product Module & in routing you are calling Products Module (which is not). Change to:

{path: 'products', loadChildren: './product/product.module#ProductModule'}

Comments

1

Try this approach, I used it for Angular 9

const routes: Routes = [
  {
    path: 'customers',
    loadChildren: () => import('./customers/customers.module').then(m => m.CustomersModule)
  },
  {
    path: 'orders',
    loadChildren: () => import('./orders/orders.module').then(m => m.OrdersModule)
  }
];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.