Internal compiler error on host binding with async pipe with Ivy
See original GitHub issueπ bug report
Is this a regression?
Yes, it works in Angular v8.2 or in v9 with Ivy disabled.
Description
In v8.2 it is possible to use the async pipe in a componentβs host binding to bind to an observable:
@Component({
host: {
'[class.active]': '(active$ | async) == true'
}
})
export class MyComponent {
active$: Observable<boolean>;
}
But this is broken in v9.
π¬ Minimal Reproduction
https://github.com/jonrimmer/ivy-binding-error
See the instructions in the README, and the source of https://github.com/jonrimmer/ivy-binding-error/blob/master/src/app/hello.component.ts
π₯ Exception or Error
ERROR in Error: Internal Error: Unexpected node
at error (ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:2721:15)
at ValueConverter.allocateSlot (ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:18820:88)
at ValueConverter.visitPipe (ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:17851:29)
at BindingPipe.visit (ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:7493:28)
at ValueConverter.AstMemoryEfficientTransformer.visitBinary (ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:7928:33)
at Binary.visit (ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:7562:28)
at ASTWithSource.visit (ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:7662:29)
at ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:13611:41
at Array.forEach (<anonymous>)
at StylingBuilder._buildSingleInputs (ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:13609:20)
at StylingBuilder._buildClassInputs (ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:13657:29)
at StylingBuilder.buildUpdateLevelInstructions (ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:13696:69)
at createHostBindingsFunction (ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:18906:26)
at baseDirectiveFields (ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:18429:43)
at Object.compileComponentFromMetadata (ivy-binding-error/node_modules/@angular/compiler/bundles/compiler.umd.js:18482:29)
at ComponentDecoratorHandler.compile (ivy-binding-error/node_modules/@angular/compiler-cli/src/ngtsc/annotations/src/component.js:512:34)
π Your Environment
Angular Version:
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ β³ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 9.0.0-rc.5
Node: 12.4.0
OS: darwin x64
Angular: 9.0.0-rc.6
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.900.0-rc.5
@angular-devkit/build-angular 0.900.0-rc.5
@angular-devkit/build-optimizer 0.900.0-rc.5
@angular-devkit/build-webpack 0.900.0-rc.5
@angular-devkit/core 9.0.0-rc.5
@angular-devkit/schematics 9.0.0-rc.5
@angular/cli 9.0.0-rc.5
@ngtools/webpack 9.0.0-rc.5
@schematics/angular 9.0.0-rc.5
@schematics/update 0.900.0-rc.5
rxjs 6.5.3
typescript 3.6.4
webpack 4.41.2
Anything else relevant?
v9 is at RC, so why are Ivyβs error messages still so unhelpful? I originally encountered this bug in a project with ~1000 components, but I had absolutely no indication which was causing the problem. I shouldnβt have to run Angular CLI in a debugger and step through it just to figure this out.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Async HostBinding in directive - angular - Stack Overflow
Now, when compiling with AoT compilation, I get Parser Error: Host binding expression cannot contain pipes in Directive . What host propertyΒ ...
Read more >Angular 9's Best Hidden Feature: Strict Template Checking
Find and report more errors than ever with Angular 9's Ivy compiler, strict template checking.
Read more >Improving Build Speed & Bundle Size with Angular Ivy | #ngconf
Join GrapeCity & ng-conf for this webinar on all the benefits that come with using the Ivy compiler. Walk away knowing how to...
Read more >Glossary - Angular
The Angular ahead-of-time (AOT) compiler converts Angular HTML and TypeScript code into efficient JavaScript code during the build phase.
Read more >Here is what you need to know about dynamic components in ...
This is because the function that performs inputs checks is generated by the compiler during compilation. This function is part of the component...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

But unintentional support is still support. We have deployed Angular v8 apps that are relying on this. If Ivy is removing it, then thatβs still a breaking change.
Whatβs more, I donβt see any elegant fixβIt seems like everywhere Iβve used this pattern I now have to go and add a new
@HostBinding('[class...])decorated boolean property, and an explicit subscribe-on-init / unsubscribe-on-destroy flow to control it, so Ivy represents a big step back in terms of support for cleanly writing reactive components.The other unhelpful error message I got while attempting to upgrade was:
Firstly, βposition 6β is ambiguous: Is that the 6th item or the 7th due to zero-based array indexing? And why doesnβt it print the actual problematic line?
It turned out the entry in question was
ApiModule.forRoot()which is returning aModuleWithProvidersobject. But why is this a problem? Isnβt that the whole idea of this pattern to return an object?I eventually figured out that In this case the
forRoot()method contained logic to create the providers array based on environment settings. Moving this logic outside of theforRoot()method fixed made things work. But why is this necessary? I can only guess that Ivy is doing some static analysis on theModuleWithProvidersresult which the presence of this logic defats. If thatβs so, a message to that effect would be far more helpful.This doesnβt seem ready to be closed. Are there plans to document this breaking change?
It probably needs to be added to the v9 update guide which currently has no mention about any noticeable changes to Async Pipes.