Hi I am running into th…

2 minute read

Hi, I am running into this problem: https://github.com/angular/angular-cli/issues/17110: my tests (jest) are still using ViewEngine. I find this a bit suspicious, as NX has good integrations for jest. Are there other people here using jest w/angular 9?

In the ticket, it is suggested to set ngcc --properties main as a post-install. But during the upgrade of NX, the postinstall was already changed like so:

ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points So I am not sure how to proceed? [angular/angular-cli] #17110 entryComponents required in tests

Responses:

If you are using angular 9 but with ivy turned off (still on viewengine like you mentioned) you do not need to run ngcc. As well, in the newest version of angular v9 they suggest you don’t even run ngcc manually yourself as the compiler will do it on the fly when needed.

So if you are still using view engine then you will need to define entry components as those have only been removed once ivy has turned on since it compiles and renders differently

I haven’t done anything specific to switch on/off ivy, so in my understanding I am using ivy (when I run the app everything works fine without entrycomponents). Only my tests seem to be using ViewEngine.

Do I need to configure the tests separately (so they also use ivy)?

That command is the solution. Jest uses a different bundle than the regular Angular stack of which the Ivy build is not triggered since nothing else uses those bundles.

A little more information here and in the issue you linked https://github.com/thymikee/jest-preset-angular/issues/353

Maybe we can fix it by using a postinstall hook “ngcc && ngcc –properties main”.

Did a migration change your postinstall to the command including “–first-only”?

Yes. I followed the angular upgrade guide (http://upgrade.angular.io|upgrade.angular.io). In the step to update “other Angular libraries”, I carried out “ng update” scripts of NX. This introduced the postinstall script, that looks exactly like so: "postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points" (so with –first-only).

Do I have to run this script manually maybe? Or change it to “ngcc && ngcc –properties main” (that seems odd)?

That only needs to be run once. I’m pretty sure it’s an Angular schematic, not a schematic by Nrwl. The postinstall hooks have been changing. With the newest version of Angular Ivy and Angular CLI, I only think we need “ngcc” in the postinstall hook. That’s for your build and serve. Since you’re using Jest for tests, you need a separate run for that every time you install a package.

The newest version of angular suggests to not run ngcc yourself manually. The angular compiler will run it when needed. How that works with tests I am unsure.

Changing the script to "postinstall": "ngcc" fixed it (I now have some other problems - a.o. with localize - but at least the tests are now running with ivy).

I am just wondering, why did the NX upgrade schematic introduce the postinstall with the extra parameters? (I checked my git logs, and the script does seem to be introduced after ng update @nrwrl/nx…)

Is it a bug, maybe like Lars mentions because the postinstall hooks have been changing? Or is this necessary for something else?

Anyways I am very happy it works! Thanks!

Updated: