Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't have nested lazy routed modules from a library #13143

Closed
Aphax opened this issue Dec 6, 2018 · 6 comments
Closed

Can't have nested lazy routed modules from a library #13143

Aphax opened this issue Dec 6, 2018 · 6 comments

Comments

@Aphax
Copy link

Aphax commented Dec 6, 2018

Bug Report or Feature Request (mark with an x)

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

Command (mark with an x)

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

Versions

$ node --version
v8.11.3

$ npm --version
5.6.0

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

Package Version

@angular-devkit/architect 0.8.8
@angular-devkit/build-angular 0.8.8
@angular-devkit/build-ng-packagr 0.10.7
@angular-devkit/build-optimizer 0.8.8
@angular-devkit/build-webpack 0.8.8
@angular-devkit/core 0.8.8
@angular-devkit/schematics 0.8.7
@angular/cdk 6.4.7
@angular/cli 6.2.7
@angular/material 6.4.7
@ngtools/json-schema 1.1.0
@ngtools/webpack 6.2.8
@schematics/angular 0.8.7
@schematics/update 0.8.7
ng-packagr 4.4.0
rxjs 6.3.3
typescript 2.7.2
webpack 4.16.4

Repro steps

git clone https://github.com/Aphax/angular6-lib-lazy-submodule.git
cd angular6-lib-lazy-submodule
npm install
ng build admin
npm run start

The log given by the failure

ERROR in Could not resolve module ./users/users.module relative to /C/Workspace/angular6-libtest/dist/admin/admin.d.ts

Desired functionality

We should be able to run an app with a lazy routed module that has itself lazy routed submodules.

Mention any other details that might be useful

The error occurs because admin.d.ts tries to resolve lazy routes of the module but is one level above in the dist/ hierarchy than the admin-routing.module that declares the routes initially.
The file admin.d.ts should be in the lib/ folder so it would work.

@alan-agius4
Copy link
Collaborator

The root cause of this is also related to #12859

@ngbot ngbot bot added this to the needsTriage milestone Dec 7, 2018
@Aphax
Copy link
Author

Aphax commented Jan 7, 2019

@alan-agius4 I don't see the direct link with the issue you're pointing to.
#12859 is about using "lazyModules" configuration to load lazy modules programmatically that aren't routed is that correct ? Nothing to do with nested lazy loaded modules with classic routing.

Maybe i'm missing some basePath configuration or something in the configuration of my "admin" library. Note that I can't find anywere a reported issue that describes the same error than me, does that mean no one ever tried to lazy load a library that has lazy loaded routing itself ?

@Aphax Aphax changed the title ng serve error when loading a lazy module that holds itself lazy routed submodules Can't have nested lazy routed modules from a library Jan 7, 2019
@alan-agius4
Copy link
Collaborator

Hi, the problem is that lazy loaded routes are being resolved using TypeScript resolution which would result in the d.ts being resolved and not the js file due to the various formats in the libraries (FESM5, FESM2015, ESM5 etc), eventually even if the resolutions to the js would work potentially this can be done by changing the forChild in the library config to point to the library name instead of the file structure it will still lead to this #12859 issue factories won't be created.

At the moment, to achieve lazy loaded modules from a library, you'd need to create a proxy module which registers the library module into the application and defines the route there rather than the library itself.

@Aphax
Copy link
Author

Aphax commented Jan 7, 2019

Ok @alan-agius4 thanks for the precisions

@alan-agius4
Copy link
Collaborator

Closing this in favour of #6373 (comment)

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants