question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lazy Loading with SSR doesn't seem to work on server

See original GitHub issue

Versions

Angular CLI: 1.5.5
Node: 8.9.1
OS: win32 x64
Angular: 5.1.0-rc.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

@angular/cdk: 5.0.0-rc.3
@angular/cli: 1.5.5
@angular/flex-layout: 2.0.0-beta.11-b01c2d7
@angular/material: 5.0.0-rc.3
@angular-devkit/build-optimizer: 0.0.34
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.39
@ngtools/json-schema: 1.1.0
@schematics/angular: 0.1.9
typescript: 2.4.2
webpack: 3.8.1

I am following the steps described in https://github.com/angular/angular-cli/wiki/stories-universal-rendering

but lazy loaded routes doesn’t seem to work on server, its showing below error in server log:

Microsoft.AspNetCore.NodeServices:Error: ERROR { Error: Uncaught (in promise): TypeError: Cannot read property './home/home.module#HomeModule' of undefined
TypeError: Cannot read property './home/home.module#HomeModule' of undefined
    at ModuleMapNgFactoryLoader.load (D:\MyProject\ClientApp\node_modules\@nguniversal\module-map-ngfactory-loader\src\module-map-ngfactory-loader.js:18:34)
    at RouterConfigLoader.loadModuleFactory (D:\MyProject\ClientApp\node_modules\@angular\router\bundles\router.umd.js:4544:72)
    at RouterConfigLoader.load (D:\MyProject\ClientApp\node_modules\@angular\router\bundles\router.umd.js:4524:52)
    at MergeMapSubscriber.project (D:\MyProject\ClientApp\node_modules\@angular\router\bundles\router.umd.js:2037:74)
    at MergeMapSubscriber._tryNext (D:\MyProject\ClientApp\node_modules\rxjs\operators\mergeMap.js:122:27)
    at MergeMapSubscriber._next (D:\MyProject\ClientApp\node_modules\rxjs\operators\mergeMap.js:112:18)
    at MergeMapSubscriber.Subscriber.next (D:\MyProject\ClientApp\node_modules\rxjs\Subscriber.js:89:18)
    at ScalarObservable._subscribe (D:\MyProject\ClientApp\node_modules\rxjs\observable\ScalarObservable.js:49:24)
    at ScalarObservable.Observable._trySubscribe (D:\MyProject\ClientApp\node_modules\rxjs\Observable.js:172:25)
    at ScalarObservable.Observable.subscribe (D:\MyProject\ClientApp\node_modules\rxjs\Observable.js:160:65)
    at resolvePromise (D:\MyProject\ClientApp\node_modules\zone.js\dist\zone-node.js:824:31)
    at resolvePromise (D:\MyProject\ClientApp\node_modules\zone.js\dist\zone-node.js:795:17)
    at D:\MyProject\ClientApp\node_modules\zone.js\dist\zone-node.js:873:17
    at ZoneDelegate.invokeTask (D:\MyProject\ClientApp\node_modules\zone.js\dist\zone-node.js:425:31)
    at Object.onInvokeTask (D:\MyProject\ClientApp\node_modules\@angular\core\bundles\core.umd.js:4786:33)
    at ZoneDelegate.invokeTask (D:\MyProject\ClientApp\node_modules\zone.js\dist\zone-node.js:424:36)
    at Zone.runTask (D:\MyProject\ClientApp\node_modules\zone.js\dist\zone-node.js:192:47)
    at drainMicroTaskQueue (D:\MyProject\ClientApp\node_modules\zone.js\dist\zone-node.js:602:35)
    at ZoneTask.invokeTask (D:\MyProject\ClientApp\node_modules\zone.js\dist\zone-node.js:503:21)
    at ZoneTask.invoke (D:\MyProject\ClientApp\node_modules\zone.js\dist\zone-node.js:488:48)
  rejection: 
   { TypeError: Cannot read property './home/home.module#HomeModule' of undefined
    at ModuleMapNgFactoryLoader.load (D:\MyProject\ClientApp\node_modules\@nguniversal\module-map-ngfactory-loader\src\module-map-ngfactory-loader.js:18:34)
    at RouterConfigLoader.loadModuleFactory (D:\MyProject\ClientApp\node_modules\@angular\router\bundles\router.umd.js:4544:72)
    at RouterConfigLoader.load (D:\MyProject\ClientApp\node_modules\@angular\router\bundles\router.umd.js:4524:52)
    at MergeMapSubscriber.project (D:\MyProject\ClientApp\node_modules\@angular\router\bundles\router.umd.js:2037:74)
    at MergeMapSubscriber._tryNext (D:\MyProject\ClientApp\node_modules\rxjs\operators\mergeMap.js:122:27)
    at MergeMapSubscriber._next (D:\MyProject\ClientApp\node_modules\rxjs\operators\mergeMap.js:112:18)
    at MergeMapSubscriber.Subscriber.next (D:\MyProject\ClientApp\node_modules\rxjs\Subscriber.js:89:18)
    at ScalarObservable._subscribe (D:\MyProject\ClientApp\node_modules\rxjs\observable\ScalarObservable.js:49:24)
    at ScalarObservable.Observable._trySubscribe (D:\MyProject\ClientApp\node_modules\rxjs\Observable.js:172:25)
    at ScalarObservable.Observable.subscribe (D:\MyProject\ClientApp\node_modules\rxjs\Observable.js:160:65)
     __zone_symbol__currentTask: 
      ZoneTask {
        _zone: [Object],
        runCount: 0,
        _zoneDelegates: null,
        _state: 'notScheduled',
        type: 'microTask',
        source: 'Promise.then',
        data: undefined,
        scheduleFn: undefined,
        cancelFn: null,
        callback: [Function],
        invoke: [Function] } },
  promise: 
   ZoneAwarePromise {
     __zone_symbol__state: 0,
     __zone_symbol__value: { TypeError: Cannot read property './home/home.module#HomeModule' of undefined
    at ModuleMapNgFactoryLoader.load (D:\MyProject\ClientApp\node_modules\@nguniversal\module-map-ngfactory-loader\src\module-map-ngfactory-loader.js:18:34)
    at RouterConfigLoader.loadModuleFactory (D:\MyProject\ClientApp\node_modules\@angular\router\bundles\router.umd.js:4544:72)
    at RouterConfigLoader.load (D:\MyProject\ClientApp\node_modules\@angular\router\bundles\router.umd.js:4524:52)
    at MergeMapSubscriber.project (D:\MyProject\ClientApp\node_modules\@angular\router\bundles\router.umd.js:2037:74)
    at MergeMapSubscriber._tryNext (D:\MyProject\ClientApp\node_modules\rxjs\operators\mergeMap.js:122:27)
    at MergeMapSubscriber._next (D:\MyProject\ClientApp\node_modules\rxjs\operators\mergeMap.js:112:18)
    at MergeMapSubscriber.Subscriber.next (D:\MyProject\ClientApp\node_modules\rxjs\Subscriber.js:89:18)
    at ScalarObservable._subscribe (D:\MyProject\ClientApp\node_modules\rxjs\observable\ScalarObservable.js:49:24)
    at ScalarObservable.Observable._trySubscribe (D:\MyProject\ClientApp\node_modules\rxjs\Observable.js:172:25)
    at ScalarObservable.Observable.subscribe (D:\MyProject\ClientApp\node_modules\rxjs\Observable.js:160:65) __zone_symbol__currentTask: [Object] } },
  zone: 
   Zone {
     _properties: { isAngularZone: true },
     _parent: 
      Zone {
        _properties: {},
        _parent: null,
        _name: '<root>',
        _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: undefined,
     scheduleFn: undefined,
     cancelFn: null,
     callback: [Function],
     invoke: [Function] } }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
asadsahicommented, Dec 15, 2017

Ahh I see, It was this line:

    const { AppServerModule, AppServerModuleNgFactory, LAZY_MODULE_MAP } = (module as any).exports;

moved inside createServerRenderer function. Previously it was outside.

Its working fine now. Thanks @naveedahmed1

0reactions
angular-automatic-lock-bot[bot]commented, Sep 7, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

title service doesn't work in SSR when the module is lazy loaded
The main idea is that, you should pass SSR map of lazy load modules, so it knows what modules do you have: app.server.module.ts...
Read more >
Code Splitting, SSR, Lazy loading React components - Medium
The components we import using loadable are broken down into separate javascript bundles by the module bundler. While writing the import ...
Read more >
What's the point of SSR when code splitting/lazy loading exists ...
js servers to do SSR and possibly scale them for high traffic load, a cost (and infrastructure) which is completely avoided with client...
Read more >
Advanced Features: Dynamic Import - Next.js
To dynamically load a component on the client side, you can use the ssr option to disable server-rendering. This is useful if an...
Read more >
Server Side rendering with Angular universal 14 - Ganatan
Generated with Angular CLI; Routing; Lazy Loading; Framework CSS Bootstrap ... that appears in the browser does not appear in the code.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found