angular-cli: ERROR in Cannot use 'in' operator to search for 'providers' in null

Please provide us with the following information:

OS?

Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

WIndows 10 Pro

Versions.

Please run ng --version. If there’s nothing outputted, please run in a Terminal: node --version and paste the result here:

angular-cli: 1.0.0-beta.24 node: 6.3.1 os: win32 x64 @angular/common: 2.4.1 @angular/compiler: 2.4.1 @angular/core: 2.4.1 @angular/forms: 2.4.1 @angular/http: 2.4.1 @angular/platform-browser: 2.4.1 @angular/platform-browser-dynamic: 2.4.1 @angular/router: 3.4.1 @angular/compiler-cli: 2.4.1

Repro steps.

Was this an app that wasn’t created using the CLI? What change did you do on your code? etc.

Brand new project created with CLI version beta 24. Adding module loading via routing loadChildren

The log given by the failure.

Normally this include a stack trace and some more information.

ERROR in Cannot use ‘in’ operator to search for ‘providers’ in null

Mention any other details that might be useful.

Issues appears when using lazy loading, for example I have HomeModule, if I were to import that to app.module.ts, and have my routing configured as:

app.routing.ts

const appRoutes: Routes = [
  {
    path: '',
    redirectTo: '/home',
    pathMatch: 'full'
  },
  {
    path: 'home',
    loadChildren: './home/home.module'
  }
];

export const Routing = RouterModule.forRoot(appRoutes);

app.module.ts

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    HomeModule,
    Routing
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Then the ERROR in Cannot use ‘in’ operator to search for ‘providers’ in null appears.


Thanks! We’ll be in touch soon.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 23 (2 by maintainers)

Commits related to this issue

Most upvoted comments

@raviganesh12 change export default RouterModule.forRoot(routes); to export const Routing = RouterModule.forRoot(routes);

And your imports for your routing on your app.module.ts needs to be changed too.

And see if that works for you.

@penleychan @clydin I still experience the same issue, I definitely don’t use ‘default’ infront of my classes and the main issue is that I don’t even get an indicator as to what file is causing this.

Could we kindly re-open the issue?

Remove the keyword default for the module routing and it works for me too.

tl;dr

don’t use the default keyword

Hi, I upgraded to angular-cli@1.0.0-beta.25.5 and am receiving the same error as discussed above. I have followed the above instructions but the error persists. I thought it was corrected. The error still does not point to any specific file either.

@st-clair-clarke Just make sure you are not using typescript keyword default for your routings. If you are still having issues you can post some of your code for us to see what’s wrong.

Also try removing the module import for HomeModule from AppModule. A module should be either lazy loaded or eagerly loaded but not both.