--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.
@nmorenor You should NOT have any imports from 'rxjs/Rx'
All imports should be like
import { BlaBla } from 'rxjs/BlaBla'
or it also allows you to import operators like this:
import 'rxjs/add/operator/blaperator';
Any attempt to
import { BlaBla } from 'rxjs/Rx'
WILL FAIL to build with new flag!
Try import 'rxjs/add/operator/catch';.
On Fri, Aug 18, 2017 at 5:34 PM, valdas [email protected] wrote:
after changing imports to import { Observable } from 'rxjs/Observable' getting this kind of errors: ERROR in /home/.../product.ts (20,18): Property 'catch' does not exist on type Observable'.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/7110#issuecomment-323335902, or mute the thread https://github.com/notifications/unsubscribe-auth/AABfR9FUSGsW-egnqeuJDP8P6Agp71U9ks5sZX3OgaJpZM4Og2NM .
While a barrel import may be undesirable in some instances, you absolutely CAN have imports directly from "rxjs/Rx". There's no reason why these should fail.
@filipesilva @hansl Can this issue be re-opened?
Reopening to investigate.
On a new project, I added this to the start of src/main.ts:
import { Observable } from 'rxjs/Rx';
console.log(Observable);
Then ran ng build --prod --build-optimizer. I had no build errors.
Can someone give me repro steps to see the issue in 1.3.1 please? Also can you do npm ls @angular-devkit/build-optimizer and tell me what version is in your project?
C:\Elastep>npm ls @angular-devkit/build-optimizer
[email protected] C:\Elastep\MCD.FOLWeb.2017.01\FolWebAdmin
`-- @angular/[email protected]
`-- @angular-devkit/[email protected]
It works if you add it in main.ts, but it does not if you add it in regular component...
@filipesilva
I just tried the same on a fresh @angular/cli 1.3.1 project and the one single thing I did to reproduce the error was to upgrade typescript from 2.3.4 to 2.4.2 and add the import like you did in src/main.ts.
Actually it's even sufficient to import the following to reproduce the error:
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/bindNodeCallback';
console.log(Observable);
@filipesilva
The error does not occur when manually removing the following part of a comment in node_modules/rxjs/observable/BoundNodeCallbackObservable.js:145 ([email protected]):
{function(...params: *): Observable}
The same happens when importing rxjs/add/observable/bindCallback as it has the same snippet in its comments.
Maybe related to https://github.com/Microsoft/TypeScript/issues/16585
Ok so this is actually related to Typescript as well. I think it might be a simple fix where something is checked more strictly inside build-optimizer.
I tried reproducing this on a new project using @angular/[email protected], [email protected] and [email protected].
Adding import { Observable } from 'rxjs/Rx'; console.log(Observable); to both main.ts or app/app.component.ts (as @Elastep suggested) did not generate an error in ng build --prod --build-optimizer.
After updating to [email protected] (like @ClemensSchneider suggested) I did get the error. I tried [email protected] and the error was gone..
So this seems the problem is Microsoft/TypeScript#16585, in typescript@~2.4.0, where trying to transform a javascript file with some comments breaks. This isn't something that we can fix in build-optimizer.
I can't speak for all the cases referenced in that issue, but it seems that it's fixed for the rxjs case in [email protected]. So the fix is to use either [email protected] or [email protected].
@filipesilva I've just upgraded to Angular CLI 1.4.0 RC2 and Typescript 2.5 RC and still get the error, however think it might be because CLI 1.4.0-rc2 locks in TS version to < 2.5.
Added a PR to allow 2.5: https://github.com/angular/angular-cli/pull/7545. The way those get resolved depends on the package manager though.
@jinder do you by chance have typescript < 2.5 in your devDependencies?
@phl3x0r no, but yarn will lock in a < 2.5 version for Angular CLI because of its fixed dependency. The next release should fix this.
@filipesilva Confirmed that this is fixed in 1.4.0 with TS 2.5.
For me its still happening, everything upgraded to last version.
ERROR in ./src/meteor-client.js Module build failed: TypeError: Cannot read property 'type' of undefined
at Object.getEffectiveTypeAnnotationNode (/home/john/demo/node_modules/typescript/lib/typescript.js:9429:17)
at assignContextualParameterTypes (/home/john/demo/node_modules/typescript/lib/typescript.js:37805:25)
at checkFunctionExpressionOrObjectLiteralMethod (/home/john/demo/node_modules/typescript/lib/typescript.js:38102:29)
at checkExpressionWorker (/home/john/demo/node_modules/typescript/lib/typescript.js:39114:28)
at checkExpression (/home/john/demo/node_modules/typescript/lib/typescript.js:39043:42)
at checkBinaryLikeExpression (/home/john/demo/node_modules/typescript/lib/typescript.js:38623:29)
at checkBinaryExpression (/home/john/demo/node_modules/typescript/lib/typescript.js:38615:20)
at checkExpressionWorker (/home/john/demo/node_modules/typescript/lib/typescript.js:39135:28)
at checkExpression (/home/john/demo/node_modules/typescript/lib/typescript.js:39043:42)
at checkBinaryLikeExpression (/home/john/demo/node_modules/typescript/lib/typescript.js:38623:29)
at checkBinaryExpression (/home/john/demo/node_modules/typescript/lib/typescript.js:38615:20)
at checkExpressionWorker (/home/john/demo/node_modules/typescript/lib/typescript.js:39135:28)
at checkExpression (/home/john/demo/node_modules/typescript/lib/typescript.js:39043:42)
at checkExpressionStatement (/home/john/demo/node_modules/typescript/lib/typescript.js:41165:13)
at checkSourceElement (/home/john/demo/node_modules/typescript/lib/typescript.js:42975:28)
at Object.forEach (/home/john/demo/node_modules/typescript/lib/typescript.js:1499:30)
at checkBlock (/home/john/demo/node_modules/typescript/lib/typescript.js:40760:16)
at checkSourceElement (/home/john/demo/node_modules/typescript/lib/typescript.js:42971:28)
at checkFunctionExpressionOrObjectLiteralMethodDeferred (/home/john/demo/node_modules/typescript/lib/typescript.js:38144:21)
at checkDeferredNodes (/home/john/demo/node_modules/typescript/lib/typescript.js:43057:25)
at checkSourceFileWorker (/home/john/demo/node_modules/typescript/lib/typescript.js:43092:17)
at checkSourceFile (/home/john/demo/node_modules/typescript/lib/typescript.js:43071:13)
@ ./src/polyfills.ts 1:0-28
@ ./src/main.ts
@ multi ./src/main.ts
This meteor-client.js file is produced by this repository https://github.com/Urigo/meteor-client-bundler.
@xriu Are you sure all your dependencies are using TS 2.5? Have you checked your yarn.lock file or npm equivalent to make sure?
Getting exactly the same error here with Angular 5 RC and Angular CLI Beta 3.
@hccampos this should be fixed now, can you give me some reproduction steps please?
@filipesilva I will try a few more things but, so far, got the error with TS2.5.3 (checked yarn.lock), Angular CLI beta 3 and Angular 5 RC0, with and without the build optimizer. Everything works fine without AOT.
Using Angular CLI 1.4.x, Angular 4.4.x works fine, but Angular 5 fails to compile with AOT saying it can't find the factories.