Skip to content

--build-optimizer errors "Cannot read property 'type' of undefined" #7110

Closed

Description

@dherges

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.

Activity

  1. dherges commented on Jul 25, 2017

    @dherges
    Author

    After #7105, I have now a fresh working copy at dherges/ng-cli-build-optimizer-issue7110.

    I will try to reproduce the issue there and then give an update.

  2. rtm commented on Jul 27, 2017

    @rtm

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

  3. dherges commented on Jul 27, 2017

    @dherges
    Author

    @rtm Yep, thanks! That's the cause!

    @filipesilva Here's the repro: https://github.com/dherges/ng-cli-build-optimizer-issue7110/commit/4a19a56da0e9a77072395f0f70de3b28b54dc1a7

    @Hanfrey FYI ... Fehler erkannt, Fehler gebannt! 🐎

  4. filipesilva commented on Jul 28, 2017

    @filipesilva
    Contributor

    This shouldn't happen, and I think it's the same as angular/devkit#51. Will investigate.

  5. self-assigned this
    on Jul 28, 2017
  6. chriszrc commented on Jul 31, 2017

    @chriszrc

    Hi,

    So are you saying you could still import the entire rxjs library:

    import { Observable } from 'rxjs/Rx';

    But still see tree-shaking and just get what you need? Would certainly be less verbose than having to import all the different operators individually given the alternative import

  7. slubowsky commented on Jul 31, 2017

    @slubowsky

    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
    
  8. added a commit that references this issue on Aug 3, 2017
    7e31be6
  9. 84 remaining items

  10. filipesilva commented on Nov 25, 2017

    @filipesilva
    Contributor

    angular/devkit#299 should fix this.

  11. filipesilva commented on Nov 27, 2017

    @filipesilva
    Contributor

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

  12. patocardo commented on Jan 19, 2018

    @patocardo

    I have the same problem and I couldn't solve it. In my case, it was caused by the use of
    import { BehaviorSubject } from 'rxjs/Rx';
    I removed it and programmed my own subject class

  13. mbark commented on Jan 22, 2018

    @mbark

    @patocardo Did you try import { BehaviorSubject } from 'rxjs/BehaviorSubject';? That works fine for me.

  14. patocardo commented on Jan 22, 2018

    @patocardo

    @mbark, thanks to the poor documentation, I didn't know of that alternative source. I'll try it.
    By the way import { BehaviorSubject } from 'rxjs/Rx'; worked fine in development, the problem only appeared online.
    Thank you for the advice

  15. fredgate commented on Jan 23, 2018

    @fredgate

    You can configure TSLint to warn when there are imports like 'rxjs/Rx'. It avoids to meet problem when you use AOT instead of JIT.

  16. added a commit that references this issue on Apr 23, 2018
    d8d4e89
  17. brobert6 commented on Apr 27, 2018

    @brobert6

    For me
    import 'rxjs/Rx';
    caused the problem. Specified the exact package that I want to import and it worked for me:
    import 'rxjs/Rx';

  18. vytautas-pranskunas- commented on May 8, 2018

    @vytautas-pranskunas-

    @jsubiratsgirbau i do not have problems importing Observable but there are problems in RXJS node_mdules in rxjs itself

  19. mateosantosdev commented on Sep 11, 2018

    @mateosantosdev

    I've solved it installing typescript@2.6.1

  20. angular-automatic-lock-bot commented on Sep 8, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  21. locked and limited conversation to collaborators on Sep 8, 2019
  22. removed their assignment
    on Jun 28, 2022
  23. added a commit that references this issue on May 29, 2026
    d700c0e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions