title: Angular 2 - Typescript Error: Cannot read property 'length' of undefined when I run ng-serve
body: <p>Here are my steps:</p>
  
  <pre><code>Install node latest v7
  Install angular cli &gt; npm install -g @angular/cli
  Open CMD and via CMD navigate to Desktop &gt; cd Desktop
  Create an angular project via angular CLI &gt; ng new testNg
  Navigate to project &gt; cd testing
  Run ng serve to launch &gt; ng serve ( response all good, page loaded)
  Navigate to app to add the code from github &gt; cd src/app
  Clone from github using SSH into the app folder &gt; git clone git@github.com:akserg/ng2-dnd.git
  Run ng server to launch &gt; ng serve ( errors)
  Found out I had a missing typescript, so install typescript &gt; npm install typescript –save
  10.2 Added on type \Testing\node_modules\typescript\lib\typescript.js on line 8735 console.log(fileName); - that is inside the createSourceFile function.
  Found out that rxjs not installed &gt; npm install rxjs –save
  Ng serve&gt; still error
  Ng build &gt; still error
  </code></pre>
  
  <p>Now that I got my new project set.</p>
  
  <p>I got this Angular drag and drop library that is not build as node_mule. I want to setup what the user has in github. </p>
  
  <p>if I do ng serve, everything compile and load perfectly.</p>
  
  <p><strong>ng --version:</strong> </p>
  
  <pre><code>angular-cli: 1.0.0-beta.28.3
  node: 7.7.1
  os: win32 x64
  @angular/common: 2.4.9
  @angular/compiler: 2.4.9
  @angular/core: 2.4.9
  @angular/forms: 2.4.9
  @angular/http: 2.4.9
  @angular/platform-browser: 2.4.9
  @angular/platform-browser-dynamic: 2.4.9
  @angular/router: 3.4.9
  @angular/compiler-cli: 2.4.9
  </code></pre>
  
  <p>So I do cd src/app
  git clone git@github.com:akserg/ng2-dnd.git
  A folder ng2-dnd is setup.</p>
  
  <p>When I run ng server I keep getting this TypeScript error. </p>
  
  <p>Cannot read property 'length' of undefined
  TypeError: Cannot read property 'length' of undefined
      at createSourceFile (C:\Users\ctarasovs\Desktop\Testing\node_modules\typescr
  ipt\lib\typescript.js:8980:109)</p>
  
  <p>I see that several people are having issue with this and can't seem how to get this working. Is it because it is set wrong, or missing a dependency. Any ideas anyone?</p>
  
  <p><strong>Here is the full errro log</strong></p>
  
  <pre><code>fallbackLoader option has been deprecated - replace with "fallback"
  loader option has been deprecated - replace with "use"
  fallbackLoader option has been deprecated - replace with "fallback"
  loader option has been deprecated - replace with "use"
  fallbackLoader option has been deprecated - replace with "fallback"
  loader option has been deprecated - replace with "use"
  fallbackLoader option has been deprecated - replace with "fallback"
  loader option has been deprecated - replace with "use"
  Cannot read property 'length' of undefined
  TypeError: Cannot read property 'length' of undefined
      at createSourceFile (C:\Users\ctarasovs\Desktop\Testing\node_modules\typescr
  ipt\lib\typescript.js:8980:109)
      at parseSourceFileWorker (C:\Users\ctarasovs\Desktop\Testing\node_modules\ty
  pescript\lib\typescript.js:8940:26)
      at Object.parseSourceFile (C:\Users\ctarasovs\Desktop\Testing\node_modules\t
  ypescript\lib\typescript.js:8899:26)
      at Object.createSourceFile (C:\Users\ctarasovs\Desktop\Testing\node_modules\
  typescript\lib\typescript.js:8727:29)
      at WebpackCompilerHost.getSourceFile (C:\Users\ctarasovs\Desktop\Testing\nod
  e_modules\@ngtools\webpack\src\compiler_host.js:210:27)
      at findSourceFile (C:\Users\ctarasovs\Desktop\Testing\node_modules\typescrip
  t\lib\typescript.js:45859:29)
      at processSourceFile (C:\Users\ctarasovs\Desktop\Testing\node_modules\typesc
  ript\lib\typescript.js:45790:27)
      at C:\Users\ctarasovs\Desktop\Testing\node_modules\typescript\lib\typescript
  .js:45901:17
      at Object.forEach (C:\Users\ctarasovs\Desktop\Testing\node_modules\typescrip
  t\lib\typescript.js:1115:30)
      at processReferencedFiles (C:\Users\ctarasovs\Desktop\Testing\node_modules\t
  ypescript\lib\typescript.js:45899:16)
      at findSourceFile (C:\Users\ctarasovs\Desktop\Testing\node_modules\typescrip
  t\lib\typescript.js:45884:21)
      at processSourceFile (C:\Users\ctarasovs\Desktop\Testing\node_modules\typesc
  ript\lib\typescript.js:45790:27)
      at processRootFile (C:\Users\ctarasovs\Desktop\Testing\node_modules\typescri
  pt\lib\typescript.js:45694:13)
      at C:\Users\ctarasovs\Desktop\Testing\node_modules\typescript\lib\typescript
  .js:45151:60
      at Object.forEach (C:\Users\ctarasovs\Desktop\Testing\node_modules\typescrip
  t\lib\typescript.js:1115:30)
      at Object.createProgram (C:\Users\ctarasovs\Desktop\Testing\node_modules\typ
  escript\lib\typescript.js:45151:16)
      at AotPlugin._setupOptions (C:\Users\ctarasovs\Desktop\Testing\node_modules\
  @ngtools\webpack\src\plugin.js:124:28)
      at new AotPlugin (C:\Users\ctarasovs\Desktop\Testing\node_modules\@ngtools\w
  ebpack\src\plugin.js:23:14)
      at Object.exports.getNonAotConfig (C:\Users\ctarasovs\Desktop\Testing\node_m
  odules\angular-cli\models\webpack-configs\typescript.js:26:13)
      at new NgCliWebpackConfig (C:\Users\ctarasovs\Desktop\Testing\node_modules\a
  ngular-cli\models\webpack-config.js:24:37)
      at Class.run (C:\Users\ctarasovs\Desktop\Testing\node_modules\angular-cli\ta
  sks\serve.js:31:29)
      at C:\Users\ctarasovs\Desktop\Testing\node_modules\angular-cli\commands\serv
  e.run.js:22:22
      at process._tickCallback (internal/process/next_tick.js:109:7)
  
  C:\Users\ctarasovs\Desktop\Testing&gt;
  </code></pre>
  
  <p><strong>Here are related links:</strong></p>
  
  <p><a href="https://github.com/angular/angular-cli/issues/5132" rel="nofollow noreferrer">https://github.com/angular/angular-cli/issues/5132</a>
  <a href="https://github.com/angular/angular-cli/issues/5053" rel="nofollow noreferrer">https://github.com/angular/angular-cli/issues/5053</a></p>
  
  <p><strong>I've tried on OS and get an error also</strong></p>
  
  <p>Here is what I got in my package.json file </p>
  
  <pre><code>{
    "name": "dnd-2.4",
    "version": "1.0.0",
    "description": "This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.0.0-rc.1.",
    "main": "karma.conf.js",
    "private": true,
    "dependencies": {
      "@angular/common": "^2.4.8",
      "@angular/compiler": "^2.4.8",
      "@angular/core": "^2.4.8",
      "@angular/forms": "^2.4.8",
      "@angular/http": "^2.4.8",
      "@angular/platform-browser": "^2.4.8",
      "@angular/platform-browser-dynamic": "^2.4.8",
      "@angular/router": "^3.4.0",
      "core-js": "^2.4.1",
      "rxjs": "^5.1.0",
      "zone.js": "^0.7.6"
    },
     "devDependencies": {
      "@angular/cli": "1.0.0-rc.1",
      "@angular/compiler-cli": "^2.4.0",
      "@types/jasmine": "2.5.38",
      "@types/node": "~6.0.60",
      "codelyzer": "~2.0.0",
      "jasmine-core": "~2.5.2",
      "jasmine-spec-reporter": "~3.2.0",
      "karma": "~1.4.1",
      "karma-chrome-launcher": "~2.0.0",
      "karma-cli": "~1.0.1",
      "karma-jasmine": "~1.1.0",
      "karma-jasmine-html-reporter": "^0.2.2",
      "karma-coverage-istanbul-reporter": "^0.2.0",
      "protractor": "~5.1.0",
      "ts-node": "~2.0.0",
      "tslint": "~4.4.2",
      "typescript": "~2.0.0"
    },
     "scripts": {
      "ng": "ng",
      "start": "ng serve",
      "build": "ng build",
      "test": "ng test",
      "lint": "ng lint",
      "e2e": "ng e2e"
    },
    "author": "",
    "license": "ISC"
  }
  </code></pre>
  
  <p><strong>Here is what I get in my Terminal:</strong>
  Here are the command I later on this day on my OS</p>
  
  <pre><code> npm init
   npm uninstall -g angular-cli
   npm uninstall angular-cli
   npm uninstall angular-cli@1.0.0-rc.1
   npm cache clean
   npm  install angular-cli@1.0.0-rc.0
  ng --version
  </code></pre>
  
  <p><strong>How to downgrade to @angular/core: 2.4.8 ?</strong></p>
  
  <pre><code>   Chriss-iMac:dragNdrop-ng2.4.9.1 christarasovs$ ng --version
      Your global Angular CLI version (1.0.0-rc.1) is greater than your local
      version (1.0.0-rc.0). The local Angular CLI version is used.
  
      To disable this warning use "ng set --global warnings.versionMismatch=false".
          _                      _                 ____ _     ___
         / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
        / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
       / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
      /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                     |___/
      @angular/cli: 1.0.0-rc.0
      node: 7.7.1
      os: darwin x64
      @angular/common: 2.4.9
      @angular/compiler: 2.4.9
      @angular/core: 2.4.9
      @angular/forms: 2.4.9
      @angular/http: 2.4.9
      @angular/platform-browser: 2.4.9
      @angular/platform-browser-dynamic: 2.4.9
      @angular/router: 3.4.9
      @angular/cli: 1.0.0-rc.0
      @angular/compiler-cli: 2.4.9
  
  
  
  Chriss-iMac:dragNdrop-ng2.4.9.1 christarasovs$ ng serve
  Your global Angular CLI version (1.0.0-rc.1) is greater than your local
  version (1.0.0-rc.0). The local Angular CLI version is used.
  
  To disable this warning use "ng set --global warnings.versionMismatch=false".
  Cannot read property 'length' of undefined
  TypeError: Cannot read property 'length' of undefined
      at createSourceFile (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:8980:109)
      at parseSourceFileWorker (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:8940:26)
      at Object.parseSourceFile (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:8899:26)
      at Object.createSourceFile (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:8727:29)
      at WebpackCompilerHost.getSourceFile (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/@ngtools/webpack/src/compiler_host.js:210:27)
      at findSourceFile (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:45859:29)
      at processSourceFile (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:45790:27)
      at /Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:45901:17
      at Object.forEach (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:1115:30)
      at processReferencedFiles (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:45899:16)
      at findSourceFile (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:45884:21)
      at processSourceFile (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:45790:27)
      at processRootFile (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:45694:13)
      at /Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:45151:60
      at Object.forEach (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:1115:30)
      at Object.createProgram (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/typescript/lib/typescript.js:45151:16)
      at AotPlugin._setupOptions (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/@ngtools/webpack/src/plugin.js:124:28)
      at new AotPlugin (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/@ngtools/webpack/src/plugin.js:23:14)
      at _createAotPlugin (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/@angular/cli/models/webpack-configs/typescript.js:55:12)
      at Object.exports.getNonAotConfig (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/@angular/cli/models/webpack-configs/typescript.js:70:19)
      at NgCliWebpackConfig.buildConfig (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/@angular/cli/models/webpack-config.js:27:37)
      at Class.run (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/@angular/cli/tasks/serve.js:37:98)
      at check_port_1.checkPort.then.port (/Users/christarasovs/Desktop/dnd/dragNdrop-ng2.4.9.1/node_modules/@angular/cli/commands/serve.js:103:26)
      at process._tickCallback (internal/process/next_tick.js:109:7)
  Chriss-iMac:dragNdrop-ng2.4.9.1 christarasovs$ 
  </code></pre>
  
  <p>My structure
  <a href="https://i.stack.imgur.com/tgnUo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tgnUo.png" alt="enter image description here"></a></p>
  
  <p><strong>Tried on Windows today and here are my steps</strong>
  Here is the exact steps I tried</p>