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
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;
}
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));
**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.
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.
I got this error due to double comma in routing as below
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.