0

I am able to use SystemJsNgModuleLoader to lazy load a local module in an angular-cli app using the advice from this comment:

How to manually lazy load a module?

And I can use an external angular library module's components using this angular library generator:

https://github.com/jvandemo/generator-angular2-library

All in the same very simple angular-cli app. But when I change the route in the provideRoutes loadChildren param from the local module to try and access the external library module, I am getting an error. It seems no value I try for the loadChildren param succeeds in accessing the external angular library.

Here is a stack trace from one of my attempts in the modtest app:

ERROR in ./src/$$_gendir lazy
Module not found: Error: Can't resolve '...\modtest\src\node_modules\lib\lib.ngfactory.ts' in '...\modtest\src\$$_gendir'
resolve '...\modtest\src\node_modules\lib\lib.ngfactory.ts' in '...\modtest\src\$$_gendir'
  using description file: ...\modtest\package.json (relative path: ./src/$$_gendir)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: ...\modtest\package.json (relative path: ./src/$$_gendir)
    using description file: ...\modtest\package.json (relative path: ./src/node_modules/lib/lib.ngfactory.ts)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        ...\modtest\src\node_modules\lib\lib.ngfactory.ts doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        ...\modtest\src\node_modules\lib\lib.ngfactory.ts.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        ...\modtest\src\node_modules\lib\lib.ngfactory.ts.js doesn't exist
      as directory
        ...\modtest\src\node_modules\lib\lib.ngfactory.ts doesn't exist
[...\modtest\src\node_modules\lib\lib.ngfactory.ts]

Notice it tries to access the node_modules directory under the src dir! And then looks for a lib.ngfactory.ts file. Does the library need to expose some ngfactory class?

Is there any way to access an external library using SystemJsNgModuleLoader? Or where is the block: angular, angular-cli, or generator-angular2-library? So I can make a feature request...

Update: To see a running example of this code, see the following repo that has instructions for usage: https://github.com/neonguru/lazyloadtest

neonguru
  • 759
  • 6
  • 16
  • 1
    create a repo with a simple setup and post it a link here – Max Koretskyi Sep 21 '17 at 04:57
  • Thanks @AngularInDepth.com, repo added to bottom of the question with instructions for usage: https://github.com/neonguru/lazyloadtest – neonguru Sep 21 '17 at 18:50
  • I got `ERROR in ../lazyloadLib/dist/lazyloadlib.d.ts Module build failed: Error: Debug Failure. False expression: Output generation failed` even without aot. Why are you importing module if you want to use it in lazy routing? https://github.com/neonguru/lazyloadtest/blob/master/lazyloadApp/src/app/app.module.ts#L20 – yurzui Sep 21 '17 at 19:26
  • @yurzui Yes I believe that is the error from 'ng serve' build. For a local lazy loaded module, you have to import the module. See TestModule. So I am doing likewise for the external SampleModule. But I am open to any suggestions to get this to work. – neonguru Sep 21 '17 at 19:56

0 Answers0