Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

cannot read property 'loadChildren' of undefined #2

Open
fulls1z3 opened this issue Feb 23, 2017 · 3 comments
Open

cannot read property 'loadChildren' of undefined #2

fulls1z3 opened this issue Feb 23, 2017 · 3 comments
Assignees
Labels
Milestone

Comments

@fulls1z3
Copy link
Owner

Please provide us with the following information:

OS?

Windows 10

Versions.

@angular/cli: 1.0.0-beta.30
node: 6.9.1
os: win32 x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7
@angular/cli: 1.0.0-beta.30
@angular/compiler-cli: 2.4.7

Repro steps.

feature.module.ts
Using @nglibs/i18n-router to provide route translations for feature modules (lazy loaded).

import { I18NRouterModule } from '@nglibs/i18n-router';

@NgModule({
  imports: [
    CommonModule,
    // RouterModule.forChild(routes)
    I18NRouterModule.forChild(routes, 'about')
  ],
  declarations: [
    AboutComponent,
    AboutUsComponent,
    AboutBananaComponent,
    AboutApplePearComponent
  ]
})

The whole solution is located on github: angular-cli branch of @nglibs/example-app.

The log given by the failure.

Can't talk about a stack trace, but hope it will be helpful:

$ ng serve
** NG Live Development Server is running on http://localhost:4200. **
Hash: ddefd75abb9ca8b82bd4                                                      Time: 18958ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.map (polyfills) 222 kB {4} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.map (main) 8.61 kB {3} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.map (styles) 10 kB {4} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.map (vendor) 3.49 MB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]

ERROR in Cannot read property 'loadChildren' of undefined
webpack: Failed to compile.

Mention any other details that might be useful.

@nglibs/i18n-router does not work with @angular-cli (yet), and giving the following error during [AoT compilation]:

ERROR in Cannot read property 'loadChildren' of undefined

I suppose @angular-cli uses @ngtools/webpack for [AoT compilation], expecting RouterModule.forChild(...) to resolve lazy-loaded modules (with loadChildren), which is replaced by I18NRouterModule.forChild(...) - providing routes for feature modules instead.

Here's the piece of code from i18n-router module line 72, which provides child routes.

                {
                    provide: ROUTES,
                    useFactory: (provideChildRoutes),
                    deps: [I18NRouterService, RAW_ROUTES, MODULE_KEY],
                    multi: true
                },
                {
                    provide: ANALYZE_FOR_ENTRY_COMPONENTS,
                    useValue: routes,
                    multi: true
                }

It provides ROUTES and ANALYZE_FOR_ENTRY_COMPONENTS to Angular the same way that the router module does (see below):

However, angular-cli seems insisting ignoring the provided child routes and firing errors.

To resolve this issue temporarily, I switched using [ng-router-loader]. Hence @angular-cli doesn't allow modifying the webpack configuration, I need to manually configure build tools (dev/prod sever, task runners, webpack, etc).

I think loadChildren should be able to recognize routes provided with ROUTES and ANALYZE_FOR_ENTRY_COMPONENTS.

@fulls1z3 fulls1z3 changed the title Cannot read property 'loadChildren' of undefined [angular-cli] Cannot read property 'loadChildren' of undefined Feb 23, 2017
@fulls1z3 fulls1z3 added the bug label Feb 23, 2017
@fulls1z3 fulls1z3 changed the title [angular-cli] Cannot read property 'loadChildren' of undefined [angular-cli] cannot read property 'loadChildren' of undefined Feb 23, 2017
@fulls1z3 fulls1z3 self-assigned this Mar 20, 2017
@fulls1z3 fulls1z3 added this to the v0.4.0-beta.2 milestone Mar 20, 2017
@fulls1z3
Copy link
Owner Author

@fulls1z3
Copy link
Owner Author

Issued a PR to fix this bug: angular/angular#15334

@fulls1z3 fulls1z3 removed this from the v0.4.0-beta.2 milestone Apr 8, 2017
@fulls1z3 fulls1z3 changed the title [angular-cli] cannot read property 'loadChildren' of undefined [bug] cannot read property 'loadChildren' of undefined Sep 3, 2017
@fulls1z3 fulls1z3 added this to the v0.2.0 milestone Sep 3, 2017
@fulls1z3 fulls1z3 removed the v2 label Sep 6, 2017
@fulls1z3 fulls1z3 modified the milestones: v4.0.0, v2.0.0, v4.0.1, v4.0.2 Sep 6, 2017
@fulls1z3 fulls1z3 changed the title [bug] cannot read property 'loadChildren' of undefined cannot read property 'loadChildren' of undefined Sep 16, 2017
@fulls1z3 fulls1z3 added v5 and removed v4 labels Jan 7, 2018
@fulls1z3 fulls1z3 modified the milestones: v4.0.2, v5.0.1 Jan 7, 2018
@martijnmelchers
Copy link

Could this please be fixed? 🙏

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants