--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.
Some more testing done, and it looks like it is not the CLI's fault, or even the build optimizer since it happens even when it is off. Basically, the latest CLI beta works with Angular 4.4.4 and fails only with Angular 5 RC0. Changing typescript versions doesn't seem to have any effect on the result.
Is there an easy way to get some better stack traces or more verbose outputs? Maybe I should open up an issue in the Angular repo instead?
@hccampos are you sure you’re not experiencing issue #7925?
@jinder well, I get that one if I use Angular 4.4.4 with the CLI 1.5.0-beta.3. If I use Angular 5 RC0 I get the weird typescript stack trace, which actually looking closer is different than in this issue:
ERROR in Error: TypeError: Cannot read property 'kind' of undefined
at nodeCanBeDecorated (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:7934:35)
at nodeIsDecorated (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:7954:16)
at nodeOrChildIsDecorated (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:7958:16)
at Object.forEach (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:1500:30)
at Object.childIsDecorated (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:7964:27)
at getClassFacts (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:51492:20)
at visitClassDeclaration (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:51517:25)
at visitTypeScript (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:51376:28)
at visitorWorker (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:51189:24)
at sourceElementVisitorWorker (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:51221:28)
at saveStateAndInvoke (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:51133:27)
at sourceElementVisitor (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:51203:20)
at visitNodes (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:49517:48)
at Object.visitLexicalEnvironment (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:49550:22)
at visitSourceFile (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:51463:53)
at saveStateAndInvoke (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:51133:27)
at transformSourceFile (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:51117:27)
at /Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:2479:86
at reduceLeft (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:2186:30)
at /Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:2479:42
at transformRoot (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:63992:82)
at Object.map (/Users/hugo/pix4d/spa/node_modules/typescript/lib/typescript.js:1693:29)
Same issue over here with @angular/cli 1.4.7 and Angular 4.4.4. Tried with TS 2.3.*, 2.4.* and 2.5.*.
ng build --app student --aot --prod --build-optimizer
ERROR in ./node_modules/rxjs/observable/BoundNodeCallbackObservable.js
Module build failed: TypeError: Cannot read property 'type' of undefined
Just found out it was caused by our own imported Angular Component library that contained wrong rxjs imports. 👍
@xriu did you get this working? I'm running into the same problem when using meteor-client-bundler.
Upgraded to ng 5.0.0-rc.8 + cli 1.5.0-rc.6 => i get the same issue. Before that, was on ng rc.6 & cli rc 3, and no problem.
Upgraded to ng 5.0.0-rc.9 + cli 1.5.0-rc.8=> i get the same issue. Please someone help me.
This seems to be coming up again so I'm reopening. Can someone provide me with a reproduction please?
According to @rtm in https://github.com/angular/angular-cli/issues/7110#issuecomment-318429320 it might be related to rxjs imports:
I had a similar problem and solved it by replacing
import { Observable } from 'rxjs/Rx';withimport { Observable } from 'rxjs/Observable';.
If someone can get me a repro with Angular 5.0.0-rc.9 + cli 1.5.0-rc.8 I'd love to take a look and try to fix it.
I fixed Replacing this . im using NG 5.rc.9 and Cli 5.rc8 import { BehaviorSubject, } from 'rxjs/BehaviorSubject'; import { Observable } from 'rxjs/Observable'; don't use "rxjs/rx"
and Run ng build --env=prod this solved your problem
Its back. Upgraded to Angular 5 and cli 1.5 and https://github.com/angular/angular-cli/issues/7110#issuecomment-319116409 came back. After initial problems it started working for me at around Angular 5.0.0-beta.4 and cli 1.4.0. Now get same error. Last known configuration it worked for me was Angular 5.0.0-rc.3 and cli 1.5.0-rc.0 (havent built prod since then)
Edit - removing buildOptimizer flag no longer solves the problem. Its broken even without buildOptimizer flag! Going to typescript 2.5.3 from 2.4.2 does solve the problem even with buildOptimizer flag (and I was using typescript >= 2.5 when I had the earlier success so it may never have worked for me with the recommended typescript 2.4.2)
Yes, angular cli 1.5 rc 8 working fine. But cli 1.5 not worked
On Nov 2, 2017 7:07 PM, "slubowsky" [email protected] wrote:
Its back. Upgraded to Angular 5 and cli 1.5 and #7110 (comment) https://github.com/angular/angular-cli/issues/7110#issuecomment-319116409 came back. After initial problems it started working for me at around Angular 5.0.0-beta.4 and cli 1.4.0. Now get same error. Last known configuration it worked for me was Angular 5.0.0-rc.3 and cli 1.5.0-rc.0 (havent built prod since then)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/7110#issuecomment-341422427, or mute the thread https://github.com/notifications/unsubscribe-auth/Ac20COO97d9u-kggWhtYbeRo3JpKe-1Uks5sycWYgaJpZM4Og2NM .
Solved: with : @angular/cli "^v1.5.0-rc.8
// import { Subject } from 'rxjs'; // bug: build optimizer
import { Subject } from 'rxjs/Subject'; // ng5 fix
import { Observable } from 'rxjs/Observable'; // ng5 fix
// import { BehaviorSubject, } from 'rxjs/BehaviorSubject'; // example
Still having the error here with @angular/cli "^v1.5.0-rc.8 with:
import 'rxjs/add/operator/bindCallback';
breaking change for me going from Angular 4 to Angular 5 when running "ng build --prod". change import 'rxjs/Rx' to import 'rxjs/add/operator/map' and for all other operators, catch, map, etc.
I also encountered this error after upgrading to angular-cli 1.5, Angular 5, TypeScript 2.4
building with command: ng build -prod --extract-css --named-chunks (-prod should be the only relevant argument)
EDIT: My code is still using chained RxJS, nothing is using lettable operators. I'm still importing with 'rxjs/add//' in a single rxjs.import.ts file, which is imported by my SharedModule.
Upgrading to TypeScript 2.5 fixed the build!
I tried other solutions with TypeScript 2.4
- change
import { X } from 'rxjs'toimport { X } from 'rxjs/X' import 'rxjs/add/observable/bindNodeCallback';
But this didn't work. I reverted the changes after upgrading to TypeScript 2.5 and the build continued to work. I think bindCallback/bindNodeCallback is a just a red herring, I think it may be an artifact of being one of the first files (due to a default alphabetic sort).
angular-cli prints a warning when using TypeScript 2.5, is there a reason not to use it?
In our case, we got rid of this error by modifying a custom decorator which was receiving a lambda as a parameter. We moved the lambda into a named function and it started building.
Just in case this is relevant to someone. After updating typescript 2.5.3 I got this webpack error
Field 'browser' doesn't contain a valid alias configuration
It was because of the way I was importing bindCallback. I had to change it like so:
// import 'rxjs/add/operator/bindCallback';
import { bindCallback } from 'rxjs/observable/bindCallback';
Which also means I had to change the way I use it:
// const callbackObservable = Observable.bindCallback(callback);
const callbackObservable = bindCallback(callback);
Upgrading typescript to 2.6.1 solved the problem. Not sure if there is a reason to look at cli warning about typescript
Same issue over here with "@angular/cli": "^1.5.0" @angular/compiler-cli": "^5.0.0"

try this
npm install typescript@latest

working fine!