Angular 6 SSR TypeError:无法读取未定义的属性“ root”

时间:2018-10-03 05:15:21

标签: angular firebase google-cloud-functions angular6 ssr

我有一个使用Angular Universal的angular 6.03项目,该项目已部署到firebase。直到几天前,一切都运转良好,但是上次部署时,我开始无法读取未定义错误的属性“ root”。

error: TypeError: Cannot read property 'root' of undefined
at new rootRoute (/Users/rebekahapelt/Projects/hapkido-website/functions/node_modules/@angular/router/bundles/router.umd.js:5390:35)
at _createClass (/Users/rebekahapelt/Projects/hapkido-website/functions/node_modules/@angular/core/bundles/core.umd.js:8445:24)
at _createProviderInstance (/Users/rebekahapelt/Projects/hapkido-website/functions/node_modules/@angular/core/bundles/core.umd.js:8417:30)
at initNgModule (/Users/rebekahapelt/Projects/hapkido-website/functions/node_modules/@angular/core/bundles/core.umd.js:8350:36)
at new NgModuleRef_ (/Users/rebekahapelt/Projects/hapkido-website/functions/node_modules/@angular/core/bundles/core.umd.js:9076:13)
at Object.createNgModuleRef (/Users/rebekahapelt/Projects/hapkido-website/functions/node_modules/@angular/core/bundles/core.umd.js:9065:16)
at NgModuleFactory_.create (/Users/rebekahapelt/Projects/hapkido-website/functions/node_modules/@angular/core/bundles/core.umd.js:11607:29)
at /Users/rebekahapelt/Projects/hapkido-website/functions/node_modules/@angular/core/bundles/core.umd.js:4375:47
at ZoneDelegate.invoke (/Users/rebekahapelt/Projects/hapkido-website/functions/node_modules/zone.js/dist/zone-node.js:388:26)
at Object.onInvoke (/Users/rebekahapelt/Projects/hapkido-website/functions/node_modules/@angular/core/bundles/core.umd.js:3890:37)

所以我有些困惑,与此有关的所有其他问题似乎都与单元测试有关。

我的server.ts文件看起来像

import 'zone.js/dist/zone-node';
import * as firebaseFunctions from 'firebase-functions';
import { enableProdMode } from '@angular/core';
import * as express from 'express';

const { AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./main');
import { ngExpressEngine } from '@nguniversal/express-engine';
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';

enableProdMode();

const app = express();

app.engine('html', ngExpressEngine({
  bootstrap:  AppServerModuleNgFactory,
  providers: [
    provideModuleMap(LAZY_MODULE_MAP)
  ]
}));

app.set('view engine', 'html');
app.set('views', __dirname);


app.get('*', (req, res) => {
  res.render('index', {req});
});


exports.ssrApp = firebaseFunctions.https.onRequest(app);

我的github存储库是https://github.com/rapelt/hapkido-website

我正在使用Angular Material,它在动画方面引起了一些有趣而烦人的问题,但我已经将这些问题修复了一段时间。

有人有任何建议吗?

1 个答案:

答案 0 :(得分:0)

经过反复思考和反复试验后,答案是Angular动画版本6.0.4不适用于服务器端应用程序。降级为6.0.3可以在本地解决问题,但不能作为已部署的应用程序解决。更新所有角度包,@ nguniversal / express-engine和打字稿修复了该项目。