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

Created on 24 Jul 2017  ·  89Comments  ·  Source: angular/angular-cli

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.

medium (days) high 1 (urgent) broken bufix

Most helpful comment

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

All 89 comments

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.

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

@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! 🐎

This shouldn't happen, and I think it's the same as https://github.com/angular/devkit/issues/51. Will investigate.

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

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

I'm getting the same error when building and using a third party dependency ng2-responsive.

ERROR in ./node_modules/rxjs/observable/BoundNodeCallbackObservable.js
Module build failed: TypeError: Cannot read property 'type' of undefined
    at Object.getEffectiveTypeAnnotationNode (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:9341:17)
    at assignContextualParameterTypes (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:41652:25)
    at checkFunctionExpressionOrObjectLiteralMethod (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:41948:29)
    at checkExpressionWorker (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:42959:28)
    at checkExpression (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:42898:42)
    at checkExpressionCached (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:42779:38)
    at checkReturnStatement (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:45418:54)
    at checkSourceElement (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:46763:28)
    at Object.forEach (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:1506:30)
    at checkBlock (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:44563:16)
    at checkSourceElement (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:46742:28)
    at checkFunctionExpressionOrObjectLiteralMethodDeferred (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:41990:21)
    at checkDeferredNodes (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:46828:25)
    at checkSourceFileWorker (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:46863:17)
    at checkSourceFile (/Users/crash/git/traveliko/traveliko-spa-frontend/node_modules/typescript/lib/typescript.js:46842:13)
    at Object.forEach (/Users/crash/git/traveliko/traveliko-spa-frontend/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
 @ ./node_modules/ng2-responsive/config/config.js
 @ ./src/$$_gendir/app/app.module.ngfactory.ts
 @ ./src/main.ts

@ multi ./src/main.ts

@bjornharvold are you using the latest version of the CLI? In this case it's 1.3.0 final.

Hi @filipesilva! Yes, that is correct.. Upgraded to 1.3.0 final today and tried the new optimize flag for the first time.

I have the same issue, version 1.3.0

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

Also seeing this same issue in 1.3.0. Please re-open.

Same issue here :)

+1
Same issue here ;)

Same thing here.

import 'rxjs/Rx';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';

Seems this is causing the issue

The same issue here. Angular CLI 1.3 with latest libraries

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

same here. Angular 5.0.0-beta.3 and CLI 1.3.0

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

only when adding --build-optimizer to my build command

I resolved these errors by refactoring all the imports, some imports we had were from angular 2 time, they are now outdated, making sure there is no whole library import, just the object and operator you need. Like below.
import {Subscription} from "rxjs/Subscription";
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/toPromise';

+1

I've already have the import {} from 'rxjs/Rx'; form on all of the files of my project but I keep having the same error. Any ideas?

@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 notifications@github.com 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.

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'; with import { 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" notifications@github.com 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' to import { 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"

e1

try this

npm install typescript@latest

s1

working fine!

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.

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

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".

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

They really should reopen this issue.

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.

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".

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.

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

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

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

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

no need to downgrade the typescript version

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

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

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

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 ?

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 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.

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.

Fixed by https://github.com/angular/devkit/pull/299, will be out on the next release.

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

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

@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

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.

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';

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

I've solved it installing [email protected]

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._

Was this page helpful?
0 / 5 - 0 ratings