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