ERROR { Error: Uncaught (in promise): Error: Cannot find module "./.../.module.ngfactory"

ERROR { Error: Uncaught (in promise): Error: Cannot find module "./.../.module.ngfactory"

我遵循了 angularfire2 文档中发布的使用通用服务器端渲染的步骤:

https://github.com/angular/angularfire2/blob/master/docs/server-side-rendering.md

我成功地编译了整个应用程序,但在 运行 编译应用程序时出现了以下错误:

ERROR { Error: Uncaught (in promise): Error: Cannot find module "./views/sessions/sessions.module.ngfactory". Error: Cannot find module "./views/sessions/sessions.module.ngfactory". at eval (webpack:///./src_lazy_namespace_object?:5:11) at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone-node.js?:387:26) at Object.onInvoke (webpack:///./node_modules/@angular/core/fesm5/core.js?:4122:33) at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone-node.js?:386:32) at Zone.run (webpack:///./node_modules/zone.js/dist/zone-node.js?:137:43) at eval (webpack:///./node_modules/zone.js/dist/zone-node.js?:871:34) at ZoneDelegate.invokeTask (webpack:///./node_modules/zone.js/dist/zone-node.js?:420:31) at Object.onInvokeTask (webpack:///./node_modules/@angular/core/fesm5/core.js?:4113:33) at ZoneDelegate.invokeTask (webpack:///./node_modules/zone.js/dist/zone-node.js?:419:36) at Zone.runTask (webpack:///./node_modules/zone.js/dist/zone-node.js?:187:47) at resolvePromise (webpack:///./node_modules/zone.js/dist/zone-node.js?:813:31) at resolvePromise (webpack:///./node_modules/zone.js/dist/zone-node.js?:770:17) at eval (webpack:///./node_modules/zone.js/dist/zone-node.js?:872:17) at ZoneDelegate.invokeTask (webpack:///./node_modules/zone.js/dist/zone-node.js?:420:31) at Object.onInvokeTask (webpack:///./node_modules/@angular/core/fesm5/core.js?:4113:33) at ZoneDelegate.invokeTask (webpack:///./node_modules/zone.js/dist/zone-node.js?:419:36) at Zone.runTask (webpack:///./node_modules/zone.js/dist/zone-node.js?:187:47) at drainMicroTaskQueue (webpack:///./node_modules/zone.js/dist/zone-node.js?:594:35) at ZoneTask.invokeTask (webpack:///./node_modules/zone.js/dist/zone-node.js?:499:21) at Server.ZoneTask.invoke (webpack:///./node_modules/zone.js/dist/zone-node.js?:484:48) rejection: { Error: Cannot find module "./views/sessions/sessions.module.ngfactory". at eval (webpack:///./src_lazy_namespace_object?:5:11) at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone-node.js?:387:26) at Object.onInvoke (webpack:///./node_modules/@angular/core/fesm5/core.js?:4122:33) at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone-node.js?:386:32) at Zone.run (webpack:///./node_modules/zone.js/dist/zone-node.js?:137:43) at eval (webpack:///./node_modules/zone.js/dist/zone-node.js?:871:34) at ZoneDelegate.invokeTask (webpack:///./node_modules/zone.js/dist/zone-node.js?:420:31) at Object.onInvokeTask (webpack:///./node_modules/@angular/core/fesm5/core.js?:4113:33) at ZoneDelegate.invokeTask (webpack:///./node_modules/zone.js/dist/zone-node.js?:419:36) at Zone.runTask (webpack:///./node_modules/zone.js/dist/zone-node.js?:187:47) code: 'MODULE_NOT_FOUND' }, promise: ZoneAwarePromise { __zone_symbol__state: 0, __zone_symbol__value: { Error: Cannot find module "./views/sessions/sessions.module.ngfactory". at eval (webpack:///./src_lazy_namespace_object?:5:11) at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone-node.js?:387:26) at Object.onInvoke (webpack:///./node_modules/@angular/core/fesm5/core.js?:4122:33) at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone-node.js?:386:32) at Zone.run (webpack:///./node_modules/zone.js/dist/zone-node.js?:137:43) at eval (webpack:///./node_modules/zone.js/dist/zone-node.js?:871:34) at ZoneDelegate.invokeTask (webpack:///./node_modules/zone.js/dist/zone-node.js?:420:31) at Object.onInvokeTask (webpack:///./node_modules/@angular/core/fesm5/core.js?:4113:33) at ZoneDelegate.invokeTask (webpack:///./node_modules/zone.js/dist/zone-node.js?:419:36) at Zone.runTask (webpack:///./node_modules/zone.js/dist/zone-node.js?:187:47) code: 'MODULE_NOT_FOUND' } }, zone: Zone { _properties: { isAngularZone: true }, _parent: Zone { _properties: {}, _parent: null, _name: '', _zoneDelegate: [Object] }, _name: 'angular', _zoneDelegate: ZoneDelegate { _taskCounts: [Object], zone: [Circular], _parentDelegate: [Object], _forkZS: null, _forkDlgt: null, _forkCurrZone: [Object], _interceptZS: null, _interceptDlgt: null, _interceptCurrZone: [Object], _invokeZS: [Object], _invokeDlgt: [Object], _invokeCurrZone: [Circular], _handleErrorZS: [Object], _handleErrorDlgt: [Object], _handleErrorCurrZone: [Circular], _scheduleTaskZS: [Object], _scheduleTaskDlgt: [Object], _scheduleTaskCurrZone: [Circular], _invokeTaskZS: [Object], _invokeTaskDlgt: [Object], _invokeTaskCurrZone: [Circular], _cancelTaskZS: [Object], _cancelTaskDlgt: [Object], _cancelTaskCurrZone: [Circular], _hasTaskZS: [Object], _hasTaskDlgt: [Object], _hasTaskDlgtOwner: [Circular], _hasTaskCurrZone: [Circular] } }, task: ZoneTask { _zone: Zone { _properties: [Object], _parent: [Object], _name: 'angular', _zoneDelegate: [Object] }, runCount: 0, _zoneDelegates: null, _state: 'notScheduled', type: 'microTask', source: 'Promise.then', data: ZoneAwarePromise { __zone_symbol__state: 0, __zone_symbol__value: [Object] }, scheduleFn: undefined, cancelFn: null, callback: [Function], invoke: [Function] } }

我正在检查,错误在文件中 webpack.server.config.js 使用 WebPack 插件 new Webpack.ContextReplacementPlugin 导致与aot延迟加载冲突。

设置和重现步骤

我为您创建了一个存储库,以便您可以重现我之前向您评论过的这个错误: https://github.com/IngAjVillalon/Angular-Universal-6-Server-Side-Render 你可以执行:

npm install

稍后

npm run build: ssr && npm run serve: ssr.

应用程序 运行 正常,但在使用应用程序时出现错误。

你能帮我吗,请告诉我们我们还有什么其他选择可以运行使用通用服务器端渲染的 aot 延迟加载?

对于延迟加载,您需要将 LAZY_MODULE_MAP 传递给渲染工厂的提供程序。在 Getting started with Angular Universal:

中查看 AngularFire2 在新的 SSR 文档中所做的工作以供审查

他们还有一个我正在这里工作的项目,它使用 AOT 和惰性模块实现 SSR:jamesdaniels/AngularFireDocs