Compiling an Angular 9 library with enableIvy: false gives an error

Viewed 871

I'm compiling a library with Angular 9/ng-packagr and it works. But if I change in angularCompilerOptions and disable Ivy "enableIvy": false then I get the following error:

ERROR: Unexpected value 'OtherLibModule in .../node_modules/other-lib-module/other-lib-module.d.ts' imported by the module 'MyModule in my-project/projects/my-lib/src/app/my.module.ts'. Please add a @NgModule annotation.

OtherLibModule is another library that I created, built with Angular 9 and "enableIvy": false.

1 Answers

The problem was that public-api.ts in otherlib was exporting the folder, not the barrel file (index). So I changed

export * from "./lib";

to

export * from "./lib/index";

in public-api.ts and it worked. The problem was that the generated otherlib-metadata.json was not including all the required metadata.

There's also a reported issue on this matter https://github.com/ng-packagr/ng-packagr/issues/355. I cannot believe it's not solved even more than two years later.

Related