Skip to content

Let 'lazyModules' option support modules from outside root in AOT mode #12859

Closed
@woppa684

Description

@woppa684

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [X] feature request

Command (mark with an x)

- [ ] new
- [X] build
- [X] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

Angular CLI: 7.0.3
Node: 8.11.3
OS: win32 x64
Angular: 7.0.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.10.3
@angular-devkit/build-angular      0.10.3
@angular-devkit/build-ng-packagr   0.10.3
@angular-devkit/build-optimizer    0.10.3
@angular-devkit/build-webpack      0.10.3
@angular-devkit/core               7.0.3
@angular-devkit/schematics         7.0.3
@angular/cli                       7.0.3
@ngtools/json-schema               1.1.0
@ngtools/webpack                   7.0.3
@schematics/angular                7.0.3
@schematics/update                 0.10.3
ng-packagr                         4.4.0
rxjs                               6.3.3
typescript                         3.1.4
webpack                            4.19.1

Repro steps

The addition of the 'lazyModules' option was something that people have been asking for for quite some time (to not "abuse" to router to create chunks). Unfortunately the lazyModules option still requires the module to be in the src folder, and therefore it is not possible to lazy load a module from a component library or an external dependency in node_modules. At the moment te only way to achieve this is to create another module that is somewhere under the src folder and imports the external module.

This works:

lazyModules: ["src/app/proxies/sample-lib.proxy"]
import { NgModule } from '@angular/core';
import { SampleLibModule, SampleLibComponent } from 'sample-lib';

@NgModule({
    imports: [SampleLibModule],
    entryComponents: [SampleLibComponent]
})
export class SampleLibProxyModule {

}

and this doesn't

lazyModules: ["projects/sample-lib/sample-lib.module"]

The log given by the failure

It curently fails with something like

ERROR in ./src/$$_lazy_route_resource lazy namespace object
Module not found: Error: Can't resolve '<mypath>/projects/sample-lib/src/lib/sample-lib.module.ngfactory.js' in <mypath>\src\$$_lazy_route_resource'

Desired functionality

lazyModules also supports including modules from node_modules and projects folders.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions