angular/ngcc-validation

ngcc ivy cdk/accordion compile error

novathore opened this issue · 3 comments

Can't compile cdk/accordion via ngcc. Compiling with specified entries working fine, for example
ngcc -t ./@angular/cdk/accordion --async -l debug -p esm5, or
ngcc -t ./@angular/cdk/accordion --async -l debug -p esm2015.

But when i tried to compile both of them at the time
ngcc -t ./@angular/cdk/accordion --async -l debug -p esm5 esm2015, ngcc failed with exception

Error: Error on worker #2: Error: Unable to write a reference to CdkAccordion in /Users/dmitry.vasiliev/Desktop/forReproduce/IvycdkAccordion/node_modules/@angular/cdk/esm2015/accordion/accordion.js from /Users/dmitry.vasiliev/Desktop/forReproduce/IvycdkAccordion/node_modules/@angular/cdk/esm2015/accordion/accordion-module.js

Here is repo for reproduce, and full stack trace in readme
https://github.com/novathore/IvycdkAccordion

@gkalpak Is this repo is a good place for the issue? Or should I write it into angular/angular (ngcc is provided by compiler-cli which is package in angular/angular repo

I just looked into this.

The error occurs when ngtsc tries to compute add a reference that would force a new import for the file. It tries to compute the logical filesystem path to the imported file, but gets null because the source file is outside the rootDirs of the program.

I believe the issue is that for libraries such as CDK the source files can be in a different tree to the entry-point path. In the case of CdkAccordion the entry-point path is node_modules/@angular/cdk/accordion but the ESM2015 source code is in node_modules/@angular/cdk/esm2015/accordion.

It appears that ngcc is incorrectly setting the rootDirs of the program to be the entry-point path whereas it should be using the package path, since source files will always be inside the package path directory, while the may not be inside the entry-point path directory.

Should be fixed by angular/angular#34212