0

I created the Jhipster application and try to add the lazy loading module, which give the module not found exception.

I follow the "https://jaseb.github.io/angular2-example/" article but still the same exception. I try myself. Please help me us to proceed further.Please find the code snippets as follows.

app.route.ts

    import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {NavbarComponent} from "./layouts/navbar/navbar.component";

export const routes: Routes = [
    { path: '', component: NavbarComponent, outlet: 'navbar'},
    { path: 'lazy', loadChildren: 'app/modules/lazy/lazy.module#LazyModule' }
];

@NgModule({
    imports: [ RouterModule.forRoot(routes) ],
    exports: [ RouterModule ]
})
export class AppRoutingModule {
}
4
  • 2
    Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. Commented Apr 2, 2017 at 16:34
  • Hi Roman, When i try to invoke the lazy url pattern it has to lazily as per my code. But am getting "app/modules/lazy/lazy.module" not found exception. When i try to run the application standalone as a angular-cli project its working, but as jhipster project it gives the module not found error. Pls help to identify the case. Commented Apr 2, 2017 at 17:01
  • I have the same problem with this repo: github.com/dancancro/jhipster-sample-app-ng2/blob/newmodules/… Did you solve it? Commented Apr 24, 2017 at 23:52
  • I have same problem for load module on routing using lazy loading. Commented Jun 18, 2017 at 18:20

2 Answers 2

1

First you must install webpack plugin angular-router-loader

npm install angular-router-loader --save-dev

then in your project directory open webpack/webpack.common.js and add angular-router-loader after awesome-typescript-loader like below

loaders: [
'angular2-template-loader',
'awesome-typescript-loader',
'angular-router-loader' // here
]

path should be without app prefix

{ path: 'lazy', loadChildren: './modules/lazy/lazy.module#LazyModule' }
Sign up to request clarification or add additional context in comments.

1 Comment

that's not working, jHipster support lazyloading or not ?
0

I was having a similar issue with lazy loading working in a straight angular app. I compared a working app with mine and noticed that I did not have "baseUrl": "./" in my tsconfig.spec.json nor my tsconfig.app.json. Once I added it it started working.

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",  **<-- this was missing**
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "src/test.ts",
    "**/*.spec.ts"
  ]
}

Hope this helps

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.