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


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 always get this error the first time I try: ERROR in Cannot read property ‘loadChildren’ of null

with ng build throws the same error

but if I use ng build --watch
and after the first build fails and I edit a file to trigger the build again it will succeed. I’ve got also the same behaviour with ng build -prod --watch

Any ideas how to get the build right the first time?

please note that I do not have any child routes/modules in my project and I don’t have any other output to see what is causing this.

Update: tested with child routes and I still get the same behaviour

Update: downgraded @angular libs to 2.4.0 from 4.0.0 and I still get the exact same behaviour, but with a different error message;

ERROR in AppModule is not an NgModule


I had multiple ts files for my routes and what I did was import all those routes in my app.routes and then concat them all together to call forRoot:

export const appRoutes = xRoutes.concat(zRoutes) etc

after putting all my routes in one single file/export const statement the error/weird build behaviour disappeared.

Answered By – jperez

Answer Checked By – Gilberto Lyons (AngularFixing Admin)

Leave a Reply

Your email address will not be published.