Lazy loading is not working together with 'import *' syntax
Please provide us with the following information:
OS?
Mac OSX El Capitan
Versions.
angular-cli: 1.0.0-beta.16 node: 5.7.1 os: darwin x64
Repro steps.
Was this an app that wasn't created using the CLI? What change did you do on your code? etc. The app was not created using the CLI. When upgrading to Angular 2 I choose to use the CLI as serving and building tool
I have this route in my app.routing.ts:
const ROUTES: Routes = [
{ path: '', redirectTo: 'analyse', pathMatch: 'full' },
{ path: 'annotate', component: AnnotateComponent },
{ path: 'fraud', component: FraudComponent },
{ path: 'info', loadChildren: 'app/info/info.module#InfoModule' },
];```
the InfoModule should be loaded lazily when navigating to it's path. But even in de --prod build there's no seperate bundle. The InfoModule is still part of the main.bundle.js.
Note that I'm still importing the InfoModule in the app.module.ts otherwise the info route does not work at all.
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 import * as moment ... components into lazy loaded modules/routes (thus removing them from the eager ones) fixed this.
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
For what's worth, I've the same problem too using angular-cli beta18
Is this related only to importing moment.js ? Because I am using angular-cli 18 and everything seems to work fine regarding lazy loading
@Mihai-B Sorry, yes it is related to importing moment.js.
This is really breaking everything.. I'm facing the exact same issue. A Fix for this is much appreciated.
I even tried with angular-cli: 1.0.0-beta.19-3 .. but the issue still exists.
Looks like this issue was introduced in beta.18
@a5hik
Looks like this issue was introduced in beta.18
I also tried with beta.17 and even 16 and have the same issue =)
Help plz, trying to lazy load one module getting same issue
Error: Cannot match any routes. URL Segment: 'admin'
i am using:
angular-cli: 1.0.0-beta.19-3 node: 6.7.0 os: win32 x64
"ng2-bootstrap": "^1.1.16",
package.json
"dependencies": { "@angular/common": "2.1.2", "@angular/compiler": "2.1.2", "@angular/core": "2.1.2", "@angular/forms": "2.1.2", "@angular/http": "2.1.2", "@angular/platform-browser": "2.1.2", "@angular/platform-browser-dynamic": "2.1.2", "@angular/router": "~3.1.0", "bootstrap": "^3.3.7", "core-js": "^2.4.1", "ng2-bootstrap": "^1.1.16", "ng2-sidebar": "^1.6.2", "rxjs": "5.0.0-beta.12", "ts-helpers": "^1.1.1", "zone.js": "^0.6.23" }, "devDependencies": { "@types/jasmine": "^2.2.30", "@types/node": "^6.0.42", "angular-cli": "1.0.0-beta.19-3", "codelyzer": "1.0.0-beta.1", "jasmine-core": "2.4.1", "jasmine-spec-reporter": "2.5.0", "karma": "1.2.0", "karma-chrome-launcher": "^2.0.0", "karma-cli": "^1.0.1", "karma-jasmine": "^1.0.2", "karma-remap-istanbul": "^0.2.1", "protractor": "4.0.9", "ts-node": "1.2.1", "tslint": "3.13.0", "typescript": "~2.0.3", "webdriver-manager": "10.2.5" }
You will have to wait for beta 20, lazy loading isn't really working yet.
@achimha What do you mean? Of course it's working, even with 3rd party libs using the workaround mentioned above.
@VinayLeaf post your question with code on stackoverflow and I can help you there
The workaround means modifying the library and if the library depends on a library which depends on a library etc. the workaround isn't really workable.
However, beta 20 is probably out very soon and then things should be much better.
agree with @ciesielskico, it's really working with workaround. Tried with latest cli
Can anyone tell me that how to use that workaround???
On 11-Nov-2016 3:45 pm, "Serhii Sol" [email protected] wrote:
agree with @ciesielskico https://github.com/ciesielskico, it's really working with workaround. Tried with latest cli
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/2496#issuecomment-259926017, or mute the thread https://github.com/notifications/unsubscribe-auth/AQo1nUyqcETorUxa08j3-wesrSvDsn4fks5q9EBWgaJpZM4KNcjN .
@VinayLeaf All you need to do is to avoid wildcard imports e.g.:
import * as moment from 'moment'
instead you need to include import into angular-cli.json e.g.:
"scripts": [
"../node_modules/moment/moment.js"
]
and then add typing for moment e.g.:
declare var moment: any;
And that's pretty it. I hope that will help you :)
PS. also you can try to import it as polyfill, but declaration of variable still should be added somewhere in types
Need to declare var instead of import * as momment from 'moment'?? Every where??
On 11-Nov-2016 3:51 pm, "Serhii Sol" [email protected] wrote:
@VinayLeaf https://github.com/VinayLeaf All you need to do is to avoid wildcard imports e.g.:
import * as moment from 'moment'
instead you need to include import into angular-cli.json e.g.:
"scripts": ["../node_modules/moment/moment.js" ]
and then add typing for moment e.g.:
declare var moment: any;
And that's pretty it. I hope that will help you :)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/2496#issuecomment-259926983, or mute the thread https://github.com/notifications/unsubscribe-auth/AQo1nYYjRRUqXfsSGuhD3q8jyjpjcwmTks5q9EGfgaJpZM4KNcjN .
@VinayLeaf only once in typings somewhere (where's your types) and then use moment as global.
@serhiisol i found 2 occurrences of import * as moment from 'moment' in following location
node_modules\awesome-typescript-loader\issues\product-designer\src\components\products node_modules\awesome-typescript-loader\issues\product-designer\src\constants
than i have replaced import * as moment from 'moment' to import * from 'moment'
i have included following code in angular-cli.json
"scripts": [ "../node_modules/moment/moment.js" ]
than i have declared declare var moment: any; in typings.d.ts
still i am getting following error
error_handler.js:47 EXCEPTION: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'admin'
am i doing something wrong?
if you want to look at my file how they looks: than got this link http://stackoverflow.com/questions/40531095/lazy-loading-not-working-with-angular-cli-webpack
@serhiisol i found that if i am not using ng2-bootstrap module than my lazy loading is working fine. and i also looked for import * as moment from 'moment' but i foundvar moment = require('moment'); i also tried to user workaround but still its not working.
@serhiisol i found solution i was doing mistake in my code, its my bad.
look at here: http://stackoverflow.com/questions/40531095/lazy-loading-not-working-with-angular-cli-webpack