Skip to content

bug: Error in Angular Universal on build SSR on Lazy Loading module import #21256

@ilprima

Description

@ilprima

Bug Report

After uploading to Ionic 5 and Angular 9 with the new lazy loading importing mode I have an error when trying to build the server.

The command used are:

"build:prod": "npm run build:ssr",
    "start:prerender": "npm run build:prerender & npm run serve:prerender",
    "serve:prerender": "node static.js",
    "build:prerender": "npm run build:prod && node dist/prerender.js"

Ionic version:

[x] 5.1.0

Current behavior:

The error thrown is:

------- Universal Project Entry File -------
src/main.server.ts
------- Entry Module Path -------
src/./app/app.server.module.ts
undefined:5
        loadChildren: '() => import('./home/home.module').then(m => m.HomePageModule)'
                                      ^

SyntaxError: Unexpected token /
    at /Users/app/dist/prerender.js:3251:70

**Expected behavior:**
<!-- Describe what the behavior would be without the bug. -->

**Steps to reproduce:**
<!--  Please explain the steps required to duplicate the issue, especially if you are able to provide a sample application. -->

Related code:

My modules are imported in the following way:

const routes: Routes =  [
    {path: '',
        children: [
            {
                path: 'home',
                children: [
                    {
                        path: '',
                        loadChildren: () => import('./home/home.module').then(m => m.HomePageModule)
                    }
                ],
            },{
                path: ':lang/home',
                children: [
                    {
                        path: '',
                        loadChildren: () => import('./home/home.module').then(m => m.HomePageModule)
                    }
                ],
            },

Other information:

Ionic info:

Ionic:

   Ionic CLI                     : 5.4.16
   Ionic Framework               : @ionic/angular 5.1.0
   @angular-devkit/build-angular : 0.901.5
   @angular-devkit/schematics    : 9.1.5
   @angular/cli                  : 9.1.5
   @ionic/angular-toolkit        : 2.2.0

Cordova:

   Cordova CLI       : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms : android 7.1.4, browser 5.0.4, ios 4.5.5
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.2, (and 13 other plugins)

Utility:

   cordova-res (update available: 0.14.0) : 0.6.0
   native-run (update available: 1.0.0)   : 0.2.8

System:

   ios-deploy : 1.9.4
   ios-sim    : 8.0.0
   NodeJS     : v10.16.3 (/usr/local/bin/node)
   npm        : 6.11.3
   OS         : macOS Catalina
   Xcode      : Xcode 11.3 Build version 11C29

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions