angular/ngcc-validation

[@momentum-ui/angular] Got: 'ERROR in Cannot read property 'visit' of undefined'

Closed this issue ยท 5 comments

I just played with this @momentum-ui/angular, seems no matter ng build or ng serve, all got the error: ERROR in Cannot read property 'visit' of undefined.

  1. Setup
    • create new project
    • install @momentum-ui/angular
    • also install lodash-es for peer dependency
  2. Import some modules from @momentum-ui/angular, like
    • import { BadgeModule } from '@momentum-ui/angular';
    • imports: [ BadgeModule.forRoot(), BrowserModule ],

Then got the error when ng build or ng serve - ERROR in Cannot read property 'visit' of undefined.
image

Is this an ngtsc error (does it show up when you do ng build?) or an actual runtime error?

yes, same error when ng build

FWIW, this is failing on this line:

@Component({
  selector: 'md-date-picker-day',
  ...
  host: {
    ...
    '[attr.ariaLabel]': '',  // <-- This line is causing the error.

It seems that the empty string causes convertPropertyBinding() to be called with expressionWithoutBuiltins being undefined, which throws when trying to visit it as AST.

(In fact, replacing that line with '[attr.ariaLabel]': '""', makes @momentum-ui/angular compile successfully with ngcc.)

BTW, if I had to guess, I would say that the intention was to have `[attr.aria-label]` as the key (instead of `[attr.ariaLabel]`), but that's unrelated to the issue ๐Ÿ˜

I am still investigating what is the best way to address this (e.g. fix the error or throw earlier with a more informative message). From a quick look I believe parsePropertyBinding() should throw when called with an empty string as expression (or maybe treat it the same as '""', which was likely the intention).

Anyway, I just wanted to give a quick update.

(Potentially related to angular/angular#30938.)

I tried with the latest versions of Angular and @moment-ui/angular and this doesn't seem to be a problem any more. (I got a different error, but that doesn't seem to be related to ngcc ๐Ÿ˜)

If you are still running into ngcc compilation failures, please open a new issue on the angular/angular repo.