0

Does anyone know why when I ngc my project, the lazy loaded modules used in the project are not being compiled/generated? This is the lazy loaded route:

children: [
    …
    {
        path: "my-apps",
        loadChildren: "carbonldp-panel/my-apps/my-apps.module#MyAppsModule",
    },
]

This is the output, no my-apps.module.ngfactory.ts file is being generated:

enter image description here

The ONLY way to generate it, is by imporing it in the routing file, but that’s not lazy loading:

import { MyAppsModule } from "carbonldp-panel/my-apps/my-apps.module”;
Alvaro Contreras
  • 313
  • 3
  • 13
  • So it pushed everything in _node_modules_? – Jai Mar 15 '17 at 06:53
  • The thing is that `carbonldp-panel` is a library of a main project. I am compiling the main project which has more dependencies ( carbonldp-panel, carbonldp, angular2-carbonldp), and it generates the ngfactory files for the angular project (angular2-carbonldp and carbonldp-panel). The main project uses some modules provided by `carbonldp-panel` and it compiles them ONLY when they are imported, but not when they are lazy loaded. – Alvaro Contreras Mar 15 '17 at 07:32

1 Answers1

2

Rollup requires a single entry point and relies on import and export statements for tree-shaking.

Lazy loading presents a problem because it can't be traced through import/export statements alone.

It's not ideal, but I suggest creating a separate entry file for the purposes of the build that includes the main app and all the lazy loaded modules:

entry.ts

import './main.ts';
import { MyAppsModule } from "carbonldp-panel/my-apps/my-apps.module";

rollup.config.js

export default {
  entry: 'entry.js',
  ...
};

[Edit]

I noticed that you deployed a module to the node_modules folder and you're now trying to re-use that module in your application in an AOT build. If its not generating the necessary factory file for your module, I would check the carbondIdp-panel module to ensure that the .metadata files for your lazy loaded module was generated as part of the build. NGC needs the metadata file to generate the factories.

I hope this helps!

Michael Kang
  • 52,003
  • 16
  • 103
  • 135