title: Karma Unit test: ERROR in Cannot read property 'length' of undefined
body: <p>I have the same problem when running karma unit tests. here is my findings</p>
  
  <p>one of my unit test will write data to a json file. and i get this error</p>
  
  <pre><code>ERROR in TypeError: Cannot read property 'length' of undefined
      at createSourceFile (...\node_modules\typescript\lib\typescript.js:15460:109)
      at parseSourceFileWorker (...\node_modules\typescript\lib\typescript.js:15389:26)
      at Object.parseSourceFile (...\node_modules\typescript\lib\typescript.js:15338:26)
      at Object.createSourceFile (...\node_modules\typescript\lib\typescript.js:15192:29)
      at new TypeScriptFileRefactor (...\node_modules\@ngtools\webpack\src\refactor.js:79:35)
      at Object.findLazyRoutes (...\node_modules\@ngtools\webpack\src\lazy_routes.js:18:22)
      at AotPlugin._findLazyRoutesInAst (...\node_modules\@ngtools\webpack\src\plugin.js:220:50)
      at _donePromise.Promise.resolve.then.then.then.then.then (...\node_modules\@ngtools\webpack\src\plugin.js:499:24)
      at process._tickCallback (internal/process/next_tick.js:109:7)
  </code></pre>
  
  <p>I added a console.log statements at <code>createSourceFile()</code> and at <code>AotPlugin._findLazyRoutesInAst</code>.</p>
  
  <p>i noticed the following in <code>AotPlugin._findLazyRoutesInAst</code>.
  <code>for (const filePath of changedFilePaths) { }</code>. I added a <code>console.log</code> statement to see what was in the changedFilePaths, I noticed the following:</p>
  
  <blockquote>
    <p>These are changedFilePaths ==><br>
    [ '.../src/polyfills.ts',<br>
    '.../src'   <strong>&lt;--- Please note the missing file name.</strong><br>
    ]</p>
  </blockquote>
  
  <p>Hence, i am getting the above error.</p>
  
  <p>This happens when i make changes to any files (irrespective of .ts files). I tried modifying a json file and the above happened.
  I tried the following:  </p>
  
  <p>in karma.conf.js (<a href="http://karma-runner.github.io/0.8/config/configuration-file.html" rel="nofollow noreferrer">as per the official config docs</a>), i added  </p>
  
  <p><code>exclude: ["./src/nonCodeRelatedData/**"]</code>.<br>
  and</p>
  
  <pre><code>files: [ {pattern: "./src/nonCodeRelatedData/**", watched: false, included: false, served: false}]
  </code></pre>
  
  <p>But no luck.</p>
  
  <p>Could someone point me the remedy to this problem? Any help is greatly appreciated.</p>