Closed damyanpetev closed 5 months ago
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
Command
build
Is this a regression?
The previous version in which this bug was not present was
17
Description
When updating to Angular 18 RC2 , libraries exports no longer seem to tree shake when consumed by apps
Minimal Reproduction
Originally reproduced in https://github.com/IgniteUI/igniteui-angular/pull/14237
Also made an minimal repo: https://github.com/damyanpetev/ng17updateTo18 (see history with each command as commit) Repo contains just a new project w/
ng new
using the current version of@angular/cli@17
& updated 18 RC. Tried both options where the lib is added first and then updated https://github.com/damyanpetev/ng17updateTo18/commits/lib-17-update18-alt, no diff in result. There are two components, the default from the library schematic and one extra with Lorem ipsum text that's only exported. The app uses just the default.In the repo run:
ng build my-lib
ng build --configuration production --verbose
In this case the second component gets bundled as well, even though it's never used/referenced in any way. For comparison run the same steps in the same state but with v17 in this branch https://github.com/damyanpetev/ng17updateTo18/tree/lib-17 and the second component is no longer included in the bundle.
Exception or Error
No response
Your Environment
Anything else relevant?
Interestingly, when switching between branches if the app is built with the dist produced by the 17 branch it tree-shakes correctly, which leads me to believe that the issue is with the library build itself, so
@angular-devkit/build-angular:ng-packagr
as a starting point. Only noticed one meaningful diff in the FESM build - declared classes now are assigned to vars that are exported, instead of direct exports: Not sure what caused it and for what reason, but it does fix the issue if I manually edit those back to the old class definitions.