angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

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

Open dherges opened this issue 9 years ago • 89 comments

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.

dherges avatar Jul 24 '17 08:07 dherges

It's odd that the the versions of typescript that they recommend don't actually work... I can also confirm bumping to Typescript 2.6.1 solved the issue.

raysuelzer avatar Nov 06 '17 04:11 raysuelzer

Yup.....Agreed....Upgrading typescript to 2.6.1, will solve the problem

siddharthashw avatar Nov 06 '17 05:11 siddharthashw

Hi there, thanks !

I had the same issue with angular 5 / cli 1.5 / typescript 2.4.2. Upgrading typescript to 2.6.1 also solved the problem, but the compiler shows a warning because it expects typescript >=2.4.2 and < 2.5.

@angular/[email protected] requires typescript@'>=2.4.2 <2.5.0' but 2.6.1 was found instead.
Using this version can result in undefined behaviour and difficult to debug problems.

Please run the following command to install a compatible version of TypeScript.

    npm install typescript@'>=2.4.2 <2.5.0'

To disable this warning run "ng set warnings.typescriptMismatch=false".

patriceo avatar Nov 06 '17 07:11 patriceo

Importing from 'rxjs/Observable' will break webSocket functionality.

PascalTemel avatar Nov 07 '17 16:11 PascalTemel

They really should reopen this issue.

raysuelzer avatar Nov 08 '17 08:11 raysuelzer

Hopefully this gets addressed as many projects will have third party dependencies that are still importing from "rxjs/Rx" and this will break your build following the guidelines the angular team has posted on updating your app.

tstrohecker avatar Nov 08 '17 14:11 tstrohecker

Updating typescript to 2.6.1 will fix this issue, but we will have warning message as below

@angular/[email protected] requires typescript@'>=2.4.2 <2.5.0' but 2.6.1 was found instead.
Using this version can result in undefined behaviour and difficult to debug problems.

Please run the following command to install a compatible version of TypeScript.

    npm install typescript@'>=2.4.2 <2.5.0'

To disable this warning run "ng set warnings.typescriptMismatch=false".

Anoop-Goudar avatar Nov 09 '17 06:11 Anoop-Goudar

After updating to Angular 5.0 and CLI 1.5 the problem si back: ./node_modules/rxjs/observable/BoundNodeCallbackObservable.js

i have to mention we haven't migrated to "lettable operators" yet, so we have to import 'rxjs/Rx'; in main.ts.

montella1507 avatar Nov 09 '17 18:11 montella1507

The problem occurred for me using Angular 5.0.1 and cli 1.5.0, I have no rxjs/Rx imports but the zone-patch-rxjs.js uses the bindCallback which causes the error.

Typescript 2.6.x solves the problem but the cli will show a warning that I use an incompatible typescript version

MrBlaise avatar Nov 10 '17 14:11 MrBlaise

Same warning as @MrBlaise & @

With Angular5, ng build --prod

with "typescript": "2.5.0" image

with "typescript": "2.6.1" image

Solution (with Warning): npm install typescript@latest

alan345 avatar Nov 10 '17 18:11 alan345

Encountered the same error, solved with upgrade to Typescript 2.6.1, disabled the Typescript mismatch warning in angular-cli.json

"warnings": { "typescriptMismatch": false }

However, this is concerning and it would be nice to know why the recommended Typescript version 2.4.2 is not working correctly with Angular 5.x + rxjs 5.5.2

sbkpilot1 avatar Nov 10 '17 22:11 sbkpilot1

Fixed changing form es5 to "target": "es6", on tsconfig.json

no need to downgrade the typescript version

salazarpp avatar Nov 11 '17 15:11 salazarpp

same issue here, had to update to TS 2.6...

born2net avatar Nov 21 '17 22:11 born2net

broken for me also! any fix that does now require to change the typescript version?

creativec0de avatar Nov 23 '17 19:11 creativec0de

I'd like to take a look at this issue again but would really like a reproduction from someone that's suffering from this problem on TS 2.4.x, preferably with third party libs as well (as @tstrohecker mentioned in https://github.com/angular/angular-cli/issues/7110#issuecomment-342832469).

I understand you all are running into this on your real projects and feel like you can't find the time to do a repro. But over 24 days since I last asked for a repro there were a total of 25 comments on this issue and not a single one offered a reproduction.

You might think the way to reproduce this is really obvious and all the information is in the issue already, but that's because you are running into it and you know what to look for. I'm not running into the issue myself. So anything less than a repro I can follow is just me grasping at straws and trying to fix what I imagine is the problem, instead of what the problem you're actually facing is.

Ideally a repro for this issue would include:

  • a repository that I can clone
  • that's using ts 2.4.x
  • that shows the error when including a third party lib and running ng build --prod
  • the error would go away after updating typescript

filipesilva avatar Nov 24 '17 09:11 filipesilva

I can no longer reproduce it. I believe it was coming from a dependency on primeng , as well as my local changes. I did not realize importing rxjs/Rxjs had been blacklisted because my tslint file from a cli initialize was old. I was made aware by someone else on my team that it was blacklisted since their project was just initialized, so I replaced all instances. As far as the third party dependency, patched I guess ?

tstrohecker avatar Nov 24 '17 13:11 tstrohecker

Here you go. I had a similar issue in my project while using ng2-tree of version 2.0.0-rc.2. Up on searching about it, landed up on this page. Error:

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

I tried to reproduce this same issue with cli-quickstart

  1. I downloaded the cli-quickstart from here
  2. Tried to do ng build --prod --build-optimizer which completed without any errors.
  3. Added ng2-tree to package.json with version "^2.0.0-rc.2".
  4. Added TreeModule to app.module.ts and imported it from ng2-tree
  5. Now tried to do a ng build --prod --build-optimizer which threw the above error.

Tried with typescript version "^2.6.0" after removing @angular/compiler-cli (@angular/[email protected] requires typescript@'>=2.4.2 <2.5.0') from the package.json . ng build --prod --build-optimizer works without any issues.

avadhootha avatar Nov 24 '17 14:11 avadhootha

@avadhootha thank you, using your repro I can verify the problem. Using ng build --prod --build-optimizer will fail with the following message:

kamik@T460p MINGW64 /d/sandbox/master-project (master)
$ ng build --prod --build-optimizer
Your global Angular CLI version (1.6.0-rc.0) is greater than your local
version (1.5.3). The local Angular CLI version is used.

To disable this warning use "ng set --global warnings.versionMismatch=false".
Date: 2017-11-24T16:32:02.180Z
Hash: c5cf2258c685c502e97e
Time: 23112ms
chunk {0} polyfills.ad37cd45a71cb38eee76.bundle.js (polyfills) 61.1 kB [initial] [rendered]
chunk {1} main.1419c5c2f716aaab2603.bundle.js (main) 415 kB [initial] [rendered]
chunk {2} styles.d41d8cd98f00b204e980.bundle.css (styles) 0 bytes [initial] [rendered]
chunk {3} inline.b16e6b2baee13a0fc20a.bundle.js (inline) 1.45 kB [entry] [rendered]

ERROR in ./node_modules/rxjs/_esm5/observable/BoundCallbackObservable.js
Module build failed: TypeError: Cannot read property 'type' of undefined
    at Object.getEffectiveTypeAnnotationNode (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:9341:18)
    at assignContextualParameterTypes (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:41652:25)
    at checkFunctionExpressionOrObjectLiteralMethod (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:41948:29)
    at checkExpressionWorker (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:42959:28)
    at checkExpression (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:42898:42)
    at checkExpressionCached (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:42779:38)
    at checkReturnStatement (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:45418:54)
    at checkSourceElement (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:46763:28)
    at Object.forEach (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:1506:30)
    at checkBlock (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:44563:16)
    at checkSourceElement (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:46742:28)
    at checkFunctionExpressionOrObjectLiteralMethodDeferred (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:41990:21)
    at checkDeferredNodes (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:46828:25)
    at checkSourceFileWorker (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:46863:17)
    at checkSourceFile (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:46842:13)
    at Object.forEach (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:1506:30)
    at getDiagnosticsWorker (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:46924:16)
    at getDiagnostics (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:46892:24)
    at Object.getEmitResolver (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:27162:13)
    at emitWorker (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:69722:69)
    at D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:69687:66
    at runWithCancellationToken (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:69779:24)
    at Object.emit (D:\sandbox\master-project\node_modules\typescript\lib\typescript.js:69687:20)
    at Object.transformJavascript (D:\sandbox\master-project\node_modules\@angular-devkit\build-optimizer\src\helpers\transform-javascript.js:80:13)
    at Object.buildOptimizer (D:\sandbox\master-project\node_modules\@angular-devkit\build-optimizer\src\build-optimizer\build-optimizer.js:92:35)
    at Object.buildOptimizerLoader (D:\sandbox\master-project\node_modules\@angular-devkit\build-optimizer\src\build-optimizer\webpack-loader.js:16:40)
 @ ./node_modules/rxjs/_esm5/observable/bindCallback.js 2:0-68
 @ ./node_modules/rxjs/_esm5/add/observable/bindCallback.js
 @ ./node_modules/rxjs/_esm5/Rx.js
 @ ./node_modules/ng2-tree/src/tree.service.js
 @ ./src/app/app.module.ngfactory.js
 @ ./src/main.ts
 @ multi ./src/main.ts

Using ng build --prod --build-optimizer=false the build will not fail.

My longer stacktrace also mentions Build Optimizer specifically.

Build Optimizer doesn't need to use the same TS version as the CLI so I think we'll just update the version there.

filipesilva avatar Nov 24 '17 16:11 filipesilva

I was running into the same issue, even with all the imports correct.

Upgrading TypeScript from 2.4.2 (default from Angular Cli) to 2.6.1 solved the issue without any other change.

celsomtrindade avatar Nov 25 '17 01:11 celsomtrindade

https://github.com/angular/devkit/pull/299 should fix this.

filipesilva avatar Nov 25 '17 10:11 filipesilva