Closed dherges closed 6 years ago
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
fol-mcdean@1.0.1 C:\Elastep\MCD.FOLWeb.2017.01\FolWebAdmin
`-- @angular/cli@1.3.1
`-- @angular-devkit/build-optimizer@0.0.13
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
(rxjs@5.4.3)
:
{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/cli@1.4.0-rc.2
, rxjs@5.4.2
and typescript@2.3.4
.
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 typescript@2.4.2
(like @ClemensSchneider suggested) I did get the error. I tried typescript@2.5.1
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 typescript@2.5.1
. So the fix is to use either typescript@2.3.x
or typescript@2.5.x
.
@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';
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
Bug Report or Feature Request (mark with an
x
)Versions.
Repro steps.
Use a mis-aligned rxjs import:
The log given by the failure.
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.