Solvedangular cli --build-optimizer errors "Cannot read property 'type' of undefined"

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

Versions.

$ ng --version
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.3.0-rc.0
node: 8.1.1
os: win32 x64
@angular/animations: 4.3.1
@angular/common: 4.3.1
@angular/compiler: 4.3.1
@angular/core: 4.3.1
@angular/forms: 4.3.1
@angular/http: 4.3.1
@angular/platform-browser: 4.3.1
@angular/platform-browser-dynamic: 4.3.1
@angular/router: 4.3.1
@angular/cli: 1.3.0-rc.0
@angular/compiler-cli: 4.3.1
rxjs@^5.4.2:
  version "5.4.2"
  resolved "<registry>/rxjs/-/rxjs-5.4.2.tgz#2a3236fcbf03df57bae06fd6972fd99e5c08fcf7"
  dependencies:
    symbol-observable "^1.0.1"

Repro steps.

Use a mis-aligned rxjs import:

import { Observable } from 'rxjs/Rx';
$ ng build --aot --prod --build-optimizer

The log given by the failure.

ERROR in ./node_modules/rxjs/observable/BoundCallbackObservable.js
Module build failed: TypeError: Cannot read property 'type' of undefined
at Object.getEffectiveTypeAnnotationNode (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:9341:17)
at assignContextualParameterTypes (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:41652:25)
at checkFunctionExpressionOrObjectLiteralMethod (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:41948:29)
at checkExpressionWorker (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:42959:28)
at checkExpression (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:42898:42)
at checkExpressionCached (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:42779:38)
at checkReturnStatement (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:45418:54)
at checkSourceElement (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:46763:28)
at Object.forEach (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:1506:30)
at checkBlock (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:44563:16)
at checkSourceElement (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:46742:28)
at checkFunctionExpressionOrObjectLiteralMethodDeferred (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:41990:21)
at checkDeferredNodes (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:46828:25)
at checkSourceFileWorker (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:46863:17)
at checkSourceFile (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:46842:13)
at Object.forEach (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:1506:30)
@ ./node_modules/rxjs/observable/bindCallback.js 2:32-68
@ ./node_modules/rxjs/add/observable/bindCallback.js
@ ./node_modules/rxjs/Rx.js
@ ./src/root.component.ts
@ ./src/$$_gendir/app.module.ngfactory.ts
@ ./src/main.ts
@ multi ./src/main.ts
ERROR in ./node_modules/rxjs/observable/BoundNodeCallbackObservable.js
Module build failed: TypeError: Cannot read property 'type' of undefined
at Object.getEffectiveTypeAnnotationNode (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:9341:17)
at assignContextualParameterTypes (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:41652:25)
at checkFunctionExpressionOrObjectLiteralMethod (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:41948:29)
at checkExpressionWorker (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:42959:28)
at checkExpression (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:42898:42)
at checkExpressionCached (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:42779:38)
at checkReturnStatement (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:45418:54)
at checkSourceElement (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:46763:28)
at Object.forEach (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:1506:30)
at checkBlock (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:44563:16)
at checkSourceElement (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:46742:28)
at checkFunctionExpressionOrObjectLiteralMethodDeferred (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:41990:21)
at checkDeferredNodes (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:46828:25)
at checkSourceFileWorker (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:46863:17)
at checkSourceFile (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:46842:13)
at Object.forEach (...\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:1506:30)
@ ./node_modules/rxjs/observable/bindNodeCallback.js 2:36-76
@ ./node_modules/rxjs/add/observable/bindNodeCallback.js
@ ./node_modules/rxjs/Rx.js
@ ./src/root.component.ts
@ ./src/$$_gendir/app.module.ngfactory.ts
@ ./src/main.ts
@ multi ./src/main.ts

Desired functionality.

Whether that rxjs syntax should be build success? I don't think so!

A better error message is good!

Mention any other details that might be useful.

31 Answers

✔️Accepted Answer

rtm
260

I had a similar problem and solved it by replacing import { Observable } from 'rxjs/Rx'; with import { Observable } from 'rxjs/Observable';.

Other Answers:

Please reopen this issue @hansl

I habe the same issue with Angular CLI 1.3.0 and Angular 4.3.4 :(

ERROR in ./node_modules/rxjs/observable/BoundCallbackObservable.js
Module build failed: TypeError: Cannot read property 'type' of undefined

I have the same issue, version 1.3.0

Im getting same issue - but dont think the import is "mis-aligned". Im using a 3rd party library which imports Observable bindCallback like this:
import 'rxjs/add/observable/bindCallback';

and then my build results in:

ERROR in ./node_modules/rxjs/observable/BoundCallbackObservable.js
Module build failed: TypeError: Cannot read property 'type' of undefined
    at Object.getEffectiveTypeAnnotationNode (C:\dev\my-app\node_modules\typescript\lib\typescript.js:9341:17)
    at assignContextualParameterTypes (C:\dev\my-app\node_modules\typescript\lib\typescript.js:41652:25)
    at checkFunctionExpressionOrObjectLiteralMethod (C:\dev\my-app\node_modules\typescript\lib\typescript.js:41948:29)
    at checkExpressionWorker (C:\dev\my-app\node_modules\typescript\lib\typescript.js:42959:28)
    at checkExpression (C:\dev\my-app\node_modules\typescript\lib\typescript.js:42898:42)
    at checkExpressionCached (C:\dev\my-app\node_modules\typescript\lib\typescript.js:42779:38)
    at checkReturnStatement (C:\dev\my-app\node_modules\typescript\lib\typescript.js:45418:54)
    at checkSourceElement (C:\dev\my-app\node_modules\typescript\lib\typescript.js:46763:28)
    at Object.forEach (C:\dev\my-app\node_modules\typescript\lib\typescript.js:1506:30)
    at checkBlock (C:\dev\my-app\node_modules\typescript\lib\typescript.js:44563:16)
    at checkSourceElement (C:\dev\my-app\node_modules\typescript\lib\typescript.js:46742:28)
    at checkFunctionExpressionOrObjectLiteralMethodDeferred (C:\dev\my-app\node_modules\typescript\lib\typescript.js:41990:21)
    at checkDeferredNodes (C:\dev\my-app\node_modules\typescript\lib\typescript.js:46828:25)
    at checkSourceFileWorker (C:\dev\my-app\node_modules\typescript\lib\typescript.js:46863:17)
    at checkSourceFile (C:\dev\my-app\node_modules\typescript\lib\typescript.js:46842:13)
    at Object.forEach (C:\dev\my-app\node_modules\typescript\lib\typescript.js:1506:30)
 @ ./node_modules/rxjs/observable/bindCallback.js 2:32-68
 @ ./node_modules/rxjs/add/observable/bindCallback.js
 @ ./node_modules/ng2-adal/services/adal.service.js
 @ ./src/$$_gendir/app/app.module.ngfactory.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

Fixed by angular/devkit#299, will be out on the next release.

More Issues: