Angular CLI ERROR in Cannot read property 'loadChildren' of null

前端 未结 11 2215
青春惊慌失措
青春惊慌失措 2021-01-01 12:24

I\'m converting a project to use angular cli and everything is working (once it\'s build) but i\'ve got a weird behaviour during build.

with ng serve I

相关标签:
11条回答
  • 2021-01-01 12:48

    I also ran into a similar issue with the Angular CLI v1.6.

    In my case I was not using .concat() or any other kind of dynamic manipulation of the router definitions.

    Rather I had a function in a data property of a route which was an anonymous arrow function. Changing this to a named exported function solved the issue for me.

    Before:

     {
        path: ':id',
        component: ProductDetailComponent,
        data: {
            breadcrumb: (data: any, params: any) => {
                let id = params['id'];
                return id === 'create' ? 'New Product' : data.product.ShortDescription;
            }
        }
    }
    

    After:

    {
        path: ':id',
        component: ProductDetailComponent,
        data: { breadcrumb: getBreadcrumb }
    }
    
    export function getBreadcrumb(data: any, params: any): string {
        let id = params['id'];
        return id === 'create' ? 'New Product' : data.product.ShortDescription;
    }
    
    0 讨论(0)
  • 2021-01-01 12:48

    In my case, this answer to a related Github issue fixed my error.

    In case it gets deleted, the fix was changing this:

    export const ROUTES = MY_ROUTES.map(TO_ANGULAR_ROUTE)
    

    to this:

    export const ROUTES = [];
    ROUTES.push(...MY_ROUTES.map(TO_ANGULAR_ROUTE));
    
    0 讨论(0)
  • 2021-01-01 12:55
    **Angular CLI ERROR in Cannot read property 'loadChildren' of null**
    

    This problem occurs when routing name is not followed camelCase naming standard. I was take dsar-config name for module, when I changed it into dsarConfig then I'm not getting any compilation error.

    0 讨论(0)
  • 2021-01-01 12:55

    in my case I have faced it when tried to concat one routes array to another:

    export const businesslogicState: Routes = BUSINESSLOGIC_ROUTES.concat(gamesRoutes);
    

    each parts of concat were Route[]

    changing one element array gamesRoutes to Route object itself didn't help, still getting the same error.

    0 讨论(0)
  • 2021-01-01 12:57

    I got this error due to double comma in routing as below

    0 讨论(0)
  • 2021-01-01 12:59

    Mocks, Components, and RouteGuards

    Another thing to check is if you're mocking/stubbing any classes in for dummy-components on a route declaration. It seems it can happen for mocked RouteGuards as well.

    0 讨论(0)
提交回复
热议问题