Skip to content

ng build AOT + lazy loading from different package #5986

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

Closed
jpguevara opened this issue Apr 17, 2017 · 12 comments
Closed

ng build AOT + lazy loading from different package #5986

jpguevara opened this issue Apr 17, 2017 · 12 comments
Assignees
Labels
freq1: low Only reported by a handful of users who observe it rarely needs: investigation Requires some digging to determine if action is needed P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity3: broken

Comments

@jpguevara
Copy link

Bug Report or Feature Request (mark with an x)

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

Versions.

Windows 7 and MacOS
$ ng --version
@angular/cli: 1.0.0
node: 7.7.2
os: win32 x64
@angular/common: 4.0.2
@angular/compiler: 4.0.2
@angular/core: 4.0.2
@angular/forms: 4.0.2
@angular/http: 4.0.2
@angular/platform-browser: 4.0.2
@angular/platform-browser-dynamic: 4.0.2
@angular/router: 4.0.2
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.2

Repro steps.

Stack Overflow Question:
http://stackoverflow.com/questions/43441732/angular-2-error-when-ng-build-aot-lazy-loading-from-different-package

Sample Repo:
https://github.com/chorew/AngularSample

Running the app

  1. clone the repo
  2. npm install
  3. npm run dev:library

const routes: Routes = [
{ path: 'library', loadChildren: '@myapp/library/src/index#ModuleAModule' } // lazy loading a module from a different package
];

The log given by the failure.

[email protected] build C:\Users\Juan.Pablo\projects\POC\AngularSample\packages\main.app
> ng build --aot

Hash: dfaf89ef3b1bb2e81c75
Time: 6307ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 158 kB {4} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 28.3 kB {3} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 9.77 kB {4} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 1.37 MB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]

ERROR in ./src/$$_gendir async
Module not found: Error: Can't resolve 'C:\Users\Juan.Pablo\projects\POC\AngularSample\packages\main.app\src\node_modules\@myapp\library\src\index.
d.ngfactory.ts' in 'C:\Users\Juan.Pablo\projects\POC\AngularSample\packages\main.app\src\$$_gendir'
 @ ./src/$$_gendir async
 @ ./~/@angular/core/@angular/core.es5.js
 @ ./src/main.ts
 @ multi ./src/main.ts

Notice how it is trying to find the lazy loaded module inside the main.app\src folder

App src path
C:\Users\Juan.Pablo\projects\POC\AngularSample\packages\main.app\src\

Lazy loaded from package
@myapp\library\src\index.d.ngfactory.ts


### Desired functionality.
<!--
What would like to see implemented?
What is the usecase?
-->

This is a sample app with 2 sub-packages.

packages/main.app
packages/library
the goal is to have a library package with different modules of the app 
and have some specific modules lazy loaded.

The use case is to be able to load modules from different packages/repos developed by different teams and pull just the needed packages from npm to configure the routes.

const routes: Routes = [
  { path: 'library', loadChildren: '@myapp/library/src/index#ModuleAModule' }, // developed by Team A
  { path: 'anotherLibrary', loadChildren: '@myapp/anotherLibrary/src/index#ModuleAModule' } // developed by Team B
];

and so on.

### Mention any other details that might be useful.
<!-- Please include a link to the repo if this is related to an OSS project. -->

Main.app was generated with ng cli
Library package is custom project using ngc and gulp
@ChenReuven
Copy link

@chorew i have same issue, with regular lazy loading.
angular-cli: v1.0
angular ver: 4.0.1

@kylecordes
Copy link

Same issue here. Lazy loading to a library packages works fine with JIT, not with AOT.

kylecordes pushed a commit to OasisDigital/angular-enterprise-example that referenced this issue Apr 19, 2017
kylecordes pushed a commit to OasisDigital/angular-enterprise-example that referenced this issue Apr 19, 2017
... because of this CLI AOT issue:

angular/angular-cli#5986

(Also work around Travis issue with recent NPM and Yarn.)
@filipesilva filipesilva added freq1: low Only reported by a handful of users who observe it rarely needs: investigation Requires some digging to determine if action is needed package4: @angular-sdk/webpack P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent severity3: broken labels May 5, 2017
@filipesilva
Copy link
Contributor

@hansl is this a bug or is there no support by design?

@kylecordes
Copy link

BTW this is still the case with CLI 1.0.4.

@jjlgjkkl
Copy link

BTW this is still the case with CLI 1.0.6

@ghost
Copy link

ghost commented Jun 13, 2017

BTW this is still the case with CLI 1.1.1

@mahmood-sajjadi
Copy link

mahmood-sajjadi commented Jul 2, 2017

BTW this is still the case with "ngtools/webpack": "^1.5.0"

@mahmood-sajjadi
Copy link

@filipesilva is this not supported by design?
would you please clarify it? there is few question related to this topic in StackOverflow without an answer and it is confusing.

@filipesilva filipesilva added P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful and removed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Aug 21, 2017
@filipesilva
Copy link
Contributor

@hansl can you chime in?

@hansl
Copy link
Contributor

hansl commented Aug 21, 2017

Hi everyone,

After some investigation and help from our compiler team, I was able to make progress to the point where it was working (see jpguevara/AngularSample#2). The last issue was that the library needs to be published with Angular as a peer dependency. By modifying the node_modules manually I was able to make ng build --aot work.

So everything can be fixed by the library side, and using the library name instead of pointing to the index file directly. It does not even require the latest version of the CLI.

Closing this issue as working-as-intended.

@hansl hansl closed this as completed Aug 21, 2017
@MitkoTschimev
Copy link

Hi @hansl,

Thank you so much for some investigation in this problem.

If i use @angular/cli and do not eject the webpack config do i still have the possibility to change somewhere the behavior like you done in the sample app?

@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 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
freq1: low Only reported by a handful of users who observe it rarely needs: investigation Requires some digging to determine if action is needed P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity3: broken
Projects
None yet
Development

No branches or pull requests

8 participants