-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Lazy loading is not working together with 'import *' syntax #2496
Comments
You should not import InfoModule nowhere else. Only reference in routes' loadChildren |
When ommitting the import in app.modules, an error occurrs that route info is unknown. |
If you import your InfoModule into app.module.ts then, you will not be using LazyLoad. Your module will be compile as main part of your app. Could you please post your info.routing.ts? |
info.routing.ts:
|
I could not find anything unusual in your code. Try this, just as best practice: const ROUTES: Routes = [ I'm also using angular-cli@beta16, but over ubuntu 16. |
Hi all, I have the same problem. I have all the routes "inlined" in a DashboardModule file that I wish to lazyload... When I removed the import in my AppModule, my app crashed with a Also, My AppModule:
And my DashboardModule:
|
@Richard87 you should set root path in DashboardModule as RouterModule.forChild([{
path: '',
component: DashboardComponent,
children: [ |
@neilhem Thanks! The routing works, but I still don't get lazy loading? (There are no reference to DashboardModule in AppModule except for the loadChildren string)... Also, it doesn't seem like
Any tips on how to troubleshoot? |
You should not import files from other lazy modules in your lazy module |
What do you mean? Like my AuthService or AuthHttp? Also, I only have 1 lazy module, DashboardModule. my other 2 modules, AppModule and LandingpageModule doesnt import anything from DashboardModule or its components... |
Double check that global & local versions of angular-cli is the latest. |
Thanks, should work:
|
Hmm, I think there are some strange "residual" files after I run I was trying to clean up the project, so I deleted all Then I added DashboardModule to AppModules imports, and ofcourse it works again.. BUT when I removed DashboardModule's import (both inside @NgModule and javascript So my conclusion is that I am importing DashboardModule in some old files, and that's why it doesnt work, but when I clean out the build files, why doesn't angular find my DashboardModule? I can't reproduce the error where angular can't find dashboard module, so I have literary no idea whats going on.. |
Same issue with 1.0.0-beta.16
and in my RouterModule.forRoot([...]): When I replace loadChildren with |
figured out the culprit; The work around is to define the library in angular-cli.json' scripts definitions, and add a However, workaround fails if other imported libraries has that Workaround to that workaround is to fork valor's ng2-bootstrap datepicker... |
I did not yet investigate, but I made a repo that can reproduce this issue: Running |
Great work figuring out the cause @aaronleeucla! This definitely should not happen and is a bug. |
Can confirm, @aaronleeucla 's workaround makes angular-cli create multiple bundles again 👍 |
For nested routing setup (Gist here) like this:
only one chunk will be created (with If I add this to the
Also note that loadChildren url in Viewer module should be I'm using To recap: For nested lazy loaded routes (Gist here) only one chunk is created if I don't add both route definitions to the root; if I do, both chunks are generated and routing works as expected. |
Thanks a lot @aaronleeucla (may you get struck with good fortune today). I couldn't figure out why Webpack was no longer generating separate chunk.js files for my lazy routes. Your solution worked for me. Moving |
Any progress with this issue @filipesilva? It has label "priority: 1 (urgent)" almost one month. It is blocking me to update my project to newest angular-cli version. |
I have the same problem with angular-cli beta18. With beta16, with an application using momentjs (and import * as moment from ''), I did not have any issues. @aaronleeucla Which version of angular-cli are you using ? Manu |
Yes, I did the exact same thing. |
#4153 should fix this problem. |
@born2net Are you using the current |
ha sorry I installed via npm, I figured it was latest as I saw .26, I guess its its not published yet? if so I will wait, np |
@born2net You can do what I have been doing to use the latest changes in my project. Check out: https://github.com/angular/angular-cli#development-hints-for-hacking-on-angular-cli I am setting up to test this new change myself. |
tried it but I could not get the symlink to work. prob cause I am on windows, will wait for npm relase to check, tx! |
FYI, here is another TimeAgo filter if you are looking to swap Moment for DateFNS and need a pipe for the template (including localisation). This replaces the angular2-moment pipes which are not currently compatible with chunking
|
seems like .28 fixed chunks, but AOT broken so can't 100% test yet. |
looks like build .28-3 still does not generate any chunks for lazy loading Sean |
@born2net for me it does and I have lot of import * as moment in my code. Try to update @ngtools/webpack to latest version. |
ha ok... let me try |
@filipesilva i'm trying to migrate to
Does not see any @angular/core/src/linker resource value here. If i comment it out, bundles created but with a lot of overhead as i understand (included all imported modules despite they are included in main bundle).Tried 1.2.4/3 - does not work too, no chunks at all. Cleared all export default /import * from code.
everything i added to webpack config related to {
test: /\.ts$/,
use: [
'@ngtools/webpack',
]
},
...
plugins: [
new AotPlugin({
tsConfigPath: 'tsconfig.json',
entryModule: path.resolve(CONFIG.APP_PATH, 'app-module', 'module#AppModule'),
skipCodeGeneration: true, // for dev mode
}),
Update: added new issue with this bug #4431 |
try this:
quick-stats.module
This worked out for me. |
How would you do lazy loading in such case, say you have lazy loaded component that rely on I tried to do something like that with |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
OS?
Versions.
angular-cli: 1.0.0-beta.16
node: 5.7.1
os: darwin x64
Repro steps.
I have this route in my app.routing.ts:
The text was updated successfully, but these errors were encountered: