无法读取null的属性'loadChildren'中的Angular CLI错误 [英] Angular CLI ERROR in Cannot read property 'loadChildren' of null
问题描述
我正在将项目转换为使用angular cli,并且一切正常(一旦构建),但是在构建过程中出现了怪异的行为.
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.
与ng serve
我总是在第一次尝试时收到此错误:无法读取null的属性'loadChildren'中的错误
with ng serve
I always get this error the first time I try: ERROR in Cannot read property 'loadChildren' of null
与ng build
会引发相同的错误
但是如果我使用ng build --watch
在第一个构建失败之后,我编辑了一个文件以再次触发该构建,它将成功.我也有与ng build -prod --watch
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?
请注意,我的项目中没有任何子路由/模块,也没有其他输出来查看导致此问题的原因.
更新:在子路由中进行了测试,但我仍然得到相同的行为
Update: tested with child routes and I still get the same behaviour
更新:将@angular库从4.0.0降级到2.4.0,我仍然可以获得完全相同的行为,但有不同的错误消息;
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;
AppModule中的错误不是NgModule
ERROR in AppModule is not an NgModule
推荐答案
我的路由有多个ts文件,我所做的就是将所有这些路由导入到我的app.routes中,然后将它们全部连接在一起以调用forRoot:
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)
等
将我的所有路由放入一个文件/export const语句后,错误/奇怪的构建行为消失了.
after putting all my routes in one single file/export const statement the error/weird build behaviour disappeared.
这篇关于无法读取null的属性'loadChildren'中的Angular CLI错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!