Angular 4构建错误:静态解析符号值时遇到错误

前端之家收集整理的这篇文章主要介绍了Angular 4构建错误:静态解析符号值时遇到错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在以前正在运行的ng2应用程序中升级Angular CLI(v1.0.0),Angular(v4.0.2)和相关软件包,以便引入更新版本的Angular Material.在由于破坏变化而与其他几个错误作斗争后,我在构建中留下了这个:

ERROR in Error encountered resolving symbol values statically. Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler (position 15:22 in the original .ts file),

resolving symbol ROUTES in /path/node_modules/@angular/router/src/router_config_loader.d.ts,

resolving symbol makeRootProviders in /path/node_modules/ui-router-ng2/lib/uiRouterNgModule.d.ts,

resolving symbol UIRouterModule.forRoot in /path/node_modules/ui-router-ng2/lib/uiRouterNgModule.d.ts,

resolving symbol AppModule in /path/src/app/app.module.ts,

resolving symbol AppModule in /path/src/app/app.module.ts

ERROR in ./src/main.ts
Module not found: Error: Can’t resolve ‘./$$_gendir/app/app.module.ngfactory’ in ‘/path/src’
@ ./src/main.ts 5:0-74
@ multi ./src/main.ts

我相信错误涉及我的UIRouter配置(在app.module.ts中),但我真的不确定:

imports: [
    BrowserModule,FormsModule,HttpModule,MaterialModule.forRoot(),FlexLayoutModule,UIRouterModule.forRoot({
        states: [
            homeState,buttonsState,colorState,fontsState,iconsState,logosState,messagingState,typographyState
        ],useHash: false
    })
],

我怀疑第一个错误会在第一个错误解决时消失.我试图创建一个返回UIRouterModule配置的函数,但这没有帮助.援助表示感谢

解决方法

我认为问题在于import语句.看起来您尝试将ROUTES导入到.ts文件中,例如:

从’@ angular / router / src / router_config_loader’导入{ROUTES};

任何导入都应该来自@ angular / router而不是’@ angular / router / src / router_config_loader’.可能发生的是您的IDE自动为您导入常量,并且它使用了错误的路径.

我有一个类似的问题,由this SO answer解决.

猜你在找的Angularjs相关文章