angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.76k stars 11.98k forks source link

always big deal to update cli #3394

Closed elvisbegovic closed 7 years ago

elvisbegovic commented 7 years ago

OS?

win10

Versions.

v22 (I update from 19-3)

Repro steps.

Cant serve, lot error and sometimes no error

The log given by the failure.

ERROR in ./src/app/app.module.ngfactory.ts
Module build failed: Error: C:/Users/e/WebstormProjects/servicyz/src/app/app.routing.ts (20,14): Exported variable 'routing' has or is using name 'ModuleWithProviders' from external module "C:/Users/e/WebstormProjects/servicyz/node_m
odules/@angular/core/src/metadata/ng_module" but cannot be named.)

I just update my cli from 19-3 to 22 and very identically app is inside I override my file with ng init

It seems problem is in my imports in app.module.ts; I import my routes like this :

 imports: [
    BrowserModule,
    HttpModule,
    routing
  ],

and my file looks like:

const APP_ROUTES : Routes = [
    {path:'', redirectTo :'/recipes', pathMatch:'full' },
    {path:'recipes', component:RecipesComponent, children:RECIPES_ROUTES},
    {path:'shopping-list', component : ShoppingListComponent, canDeactivate:[ShoppingListQuitGuard]},
    {path:'formst', component:TemplateDrivenComponent},
    {path:'formsd', component:DataDrivenComponent}
];
export const routing = RouterModule.forRoot(APP_ROUTES);

So before in 19-3 it works but now when I run ng serve, the cli compile completly but before webpack:bundle is now VALID I have this error above

And the strange behavior is when I remove this routing from imports, it blocking at 20% without any reaction without any error !

Please apologize but updating cli is every time BIG CHALLENGE ! always errors by example above I don't understand why this ModuleWithProviders tell me it's using from external module!

Update

Ok I don't understand this code was working before but I find solution for this version of angular simply export RouterModule like this:

@NgModule({
imports: [ RouterModule.forRoot(APP_ROUTES) ],
exports: [ RouterModule ]
})
export class AppRoutingModule {}

Was Insignifiant message error don't help me to find this solution

hansl commented 7 years ago

Try to install beta 22-1. 22 was never released and was blocked during testing in experimental.

idollobi commented 7 years ago

The generate error for your initial code was essentially caused by un-explicitly typed variable "routing".

Update to this line and it will be fine. export const routing: Routes = RouterModule.forRoot(APP_ROUTES);

elvisbegovic commented 7 years ago

I think routing isn't Routes type, only APP_ROUTES is. but if I add type ModuleWithProviders it works ! And the problem is I don't understand why need specify type while type are optionals in TS maybe ts bug...

angular-automatic-lock-bot[bot] commented 5 years ago

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.