title: No module factory available for dependency type: ContextElementDependency
body: <p>I am changing the structure of my angular-4 app with lazy loaded modules and facing an error when I run</p>
  
  <pre><code>ng build
  </code></pre>
  
  <p>The error:</p>
  
  <blockquote>
    <p>Error: No module factory available for dependency type: ContextElementDependency</p>
  </blockquote>
  
  <p>This error do not appear when I am commenting out the lazy-loaded modules. </p>
  
  <p>This is my <em>package.json</em>:</p>
  
  <pre><code>{
    "name": "picosmos",
    "version": "0.0.0",
    "license": "MIT",
    "scripts": {
      "ng": "ng",
      "start": "ng serve",
      "build": "ng build",
      "test": "ng test",
      "lint": "ng lint",
      "e2e": "ng e2e"
    },
    "private": true,
    "dependencies": {
      "@angular/animations": "^4.2.4",
      "@angular/common": "^4.2.4",
      "@angular/compiler": "^4.2.4",
      "@angular/core": "^4.2.4",
      "@angular/forms": "^4.2.4",
      "@angular/http": "^4.2.4",
      "@angular/platform-browser": "^4.2.4",
      "@angular/platform-browser-dynamic": "^4.2.4",
      "@angular/router": "^4.2.4",
      "angular-in-memory-web-api": "~0.3.1",
      "core-js": "^2.4.1",
      "es6-promise": "3.0.2",
      "lodash": "4.17.4",
      "moment": "^2.18.1",
      "moment-timezone": "^0.5.13",
      "papaparse": "4.3.3",
      "rxjs": "^5.4.2",
      "systemjs": "0.19.39",
      "webpack": "^3.6.0",
      "zone.js": "^0.8.14"
    },
    "devDependencies": {
      "@angular/cli": "^1.4.2",
      "@angular/compiler-cli": "4.2.4",
      "@angular/language-service": "^4.2.4",
      "@types/jasmine": "~2.5.53",
      "@types/jasminewd2": "~2.0.2",
      "@types/node": "~6.0.60",
      "codelyzer": "~3.1.1",
      "gulp": "3.9.1",
      "gulp-less": "3.3.2",
      "gulp-typescript": "3.2.0",
      "http-server": "^0.9.0",
      "jasmine-core": "~2.6.2",
      "jasmine-spec-reporter": "~4.1.0",
      "karma": "~1.7.0",
      "karma-chrome-launcher": "~2.1.1",
      "karma-cli": "~1.0.1",
      "karma-coverage-istanbul-reporter": "^1.2.1",
      "karma-jasmine": "~1.1.0",
      "karma-jasmine-html-reporter": "^0.2.2",
      "less": "2.7.2",
      "protractor": "~5.1.2",
      "ts-node": "~3.2.0",
      "tslint": "~5.3.2",
      "typescript": "~2.3.3"
    }
  }
  </code></pre>
  
  <p>Global installed are (among others):</p>
  
  <ul>
  <li>TypeScript 2.4.2</li>
  <li>webpack 3.6.0</li>
  <li>@angular/cli 1.4.2</li>
  </ul>
  
  <p>I found some issue Threads on GitHub, but no solutions helped me. I tried to reinstall <code>webpack</code> and <code>@angular/cli</code>. Nothing helped.</p>
  
  <p>Any suggestions/experiences/tips with this?</p>
  
  <hr>
  
  <p>This are my Route-Config for my <code>AppModule</code></p>
  
  <pre><code>const appRoutes: Routes = [
  
  // These routes cause the compile-error (ng build)
    { path: "Finances", loadChildren: "./Finances/finances.module#FinancesModule" },
    { path: "Test", loadChildren: "./Test/test.module#TestModule" },
    { path: "Media", loadChildren: "./Media/media.module#MediaModule" },
  
  //These routes work
    { path: "Dashboard", component: DashboardComponent },
    { path: "Error/:errorId", component: ErrorComponent },
    { path: "", pathMatch: "full", redirectTo: "Dashboard"},
    { path: "**", redirectTo: "/Error/http404" }
  ];
  </code></pre>
  
  <p>e.g. <code>test.module.ts</code>:</p>
  
  <pre><code>// imports
  
  const testRoutes: Routes = [
      {
          path: "",
          component: IndexComponent,
      },
  ];
  
  @NgModule({
      imports: [
          RouterModule.forChild(
              testRoutes
          ),
          HttpModule,
          CommonModule,
          FormsModule,
          SharedModule
      ],
      declarations: [
          IndexComponent
      ],
      bootstrap: [
          IndexComponent
      ]
  })
  export class TestModule {
  }
  </code></pre>