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 loaded module not rendered with Server Side Rendering

See original GitHub issue

I’m submitting a…


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x ] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

I added a lazy-loaded module named “user” & a simple component named “admin”. Routing with lazy-loaded module is working fine, am getting all the things properly, but the content in the lazy-loaded module is not being rendered in the page source, I mean, if I right click & view page source, I can’t get my content of lazy module rendered. Instead am getting just the router-outlet tags. But there is no issue with the normal component. **** Also am getting an error in cmd with “Uncaught (in promise): ReferenceError: System is not defined at SystemJsNgModuleLoader.loadFactory”. ***** Also importing “ModuleMapLoaderModule” crashes the entire app for which there will be no issues while building it, but when running in the browser, am getting some errors too without the app being served. Am hereby attaching the Github repo link & snapshots of the issue. I was using the following links to get this working:

https://github.com/angular/angular-cli/wiki/stories-universal-rendering

https://medium.com/@evertonrobertoauler/angular-5-universal-with-transfer-state-using-angular-cli-19fe1e1d352c

*** If this was an error on my part like it was due to some code missing from my side, please pardon me & help me fix it. I have checked for issue, but I couldn’t find a solution. So please help me to get this resolved… *****

Expected behavior

The contents of the lazy-loaded module should also be rendered in the page source. Isn’t right, according to Angular Universal. Currently, there is no issue with normal components, but contents of lazy-loaded module must be rendered in the page source.

Minimal reproduction of the problem with instructions

Github link to project https://github.com/rogerjacob/angular5-ssr-demo.git

Normal component - contents are getting rendered in page source normal-component

normal-component-1

Lazy-loaded module - only router-outlet tags are being rendered instead of actual content lazy-loaded-module

What is the motivation / use case for changing the behavior?

Environment


Angular version: 5.2.0

"dependencies": {
    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/platform-server": "^5.2.3",
    "@angular/router": "^5.2.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19"
  },
"devDependencies": {
    "@angular/cli": "1.6.7",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "npm-run-all": "^4.1.2",
    "protractor": "~5.1.2",
    "ts-loader": "^3.4.0",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3",
    "webpack-node-externals": "^1.6.0"
  }

Browser:
- [x] Chrome (desktop) version 63.0.3239.132 (Official Build) (64-bit)
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: v6.9.1  
- Platform: Windows 

Others:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
trotylcommented, Feb 10, 2018

I don’t think you were following the story.

// Note this!
import {ModuleMapLoaderModule} from '@nguniversal/module-map-ngfactory-loader';

@NgModule({
  imports: [
    // Note this!
    ModuleMapLoaderModule // <-- *Important* to have lazy-loaded routes work
  ],
})
export class AppServerModule {}

Where @nguniversal/module-map-ngfactory-loader is a standalone package lies in angular/universal.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 29, 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

Lazy-loaded Angular modules don't get server side rendered ...
Lazy -loaded Angular modules don't get server side rendered with @nguniversal, while client side routing and rendering works.
Read more >
Angular SEO Guide- Angular Universal with Server Side ...
In this article, we will discuss how we can make angular applications will be SEO friendly as google crawls the pages based on...
Read more >
angular/universal - Gitter
lazy loading works with server rendering. that's not the problem. the problem is how the app is structured with lazy loading and it...
Read more >
Advanced Features: Dynamic Import - Next.js
With no SSR ... To dynamically load a component on the client side, you can use the ssr option to disable server-rendering. This...
Read more >
React Lazy Loading: The Best Complete Guide - CopyCat Blog
React lazy() and Suspense are not yet available for server-side rendering. If you want to do code-splitting in a server-side rendered app, ...
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