Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library tree-shaking doesn't seem to work with 18 RC #27662

Closed
1 task done
damyanpetev opened this issue May 20, 2024 · 1 comment · Fixed by #27667
Closed
1 task done

Library tree-shaking doesn't seem to work with 18 RC #27662

damyanpetev opened this issue May 20, 2024 · 1 comment · Fixed by #27667
Assignees
Labels
area: angular/build freq1: low Only reported by a handful of users who observe it rarely severity5: regression type: bug/fix

Comments

@damyanpetev
Copy link

damyanpetev commented May 20, 2024

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

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 IgniteUI/igniteui-angular#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:

  1. ng build my-lib
  2. ng build --configuration production --verbose
  3. Inspect the dist main bundle and look for the Lorem Ipsum text

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

Angular CLI: 18.0.0-rc.2
Node: 20.13.1
Package Manager: npm 10.5.2
OS: linux x64

Angular: 18.0.0-rc.2
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1800.0-rc.2
@angular-devkit/build-angular   18.0.0-rc.2
@angular-devkit/core            18.0.0-rc.2
@angular-devkit/schematics      18.0.0-rc.2
@schematics/angular             18.0.0-rc.2
ng-packagr                      18.0.0-rc.0
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.6

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:
image
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.

@alan-agius4 alan-agius4 added type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity5: regression area: angular/build labels May 21, 2024
@alan-agius4 alan-agius4 self-assigned this May 21, 2024
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue May 21, 2024
…perties or blocks emitted by esbuild

Prior to this commit, class expressions emitted by esbuild that have static blocks or properties were not being properly wrapped. This caused the class to become non-treeshakable.

Closes angular#27662
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue May 21, 2024
…perties or blocks emitted by esbuild

Prior to this commit, class expressions emitted by esbuild that have static blocks or properties were not being properly wrapped. This caused the class to become non-treeshakable.

Closes angular#27662
alan-agius4 added a commit that referenced this issue May 21, 2024
…perties or blocks emitted by esbuild

Prior to this commit, class expressions emitted by esbuild that have static blocks or properties were not being properly wrapped. This caused the class to become non-treeshakable.

Closes #27662
alan-agius4 added a commit that referenced this issue May 21, 2024
…perties or blocks emitted by esbuild

Prior to this commit, class expressions emitted by esbuild that have static blocks or properties were not being properly wrapped. This caused the class to become non-treeshakable.

Closes #27662

(cherry picked from commit ac9fc72)
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: angular/build freq1: low Only reported by a handful of users who observe it rarely severity5: regression type: bug/fix
Projects
None yet
2 participants