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

Unused down-levelled ES2015 classes are not tree shaken away #14997

Closed
kumaresan-subramani opened this issue Jul 4, 2019 · 10 comments
Closed
Labels
freq1: low Only reported by a handful of users who observe it rarely help wanted severity3: broken type: bug/fix
Milestone

Comments

@kumaresan-subramani
Copy link

kumaresan-subramani commented Jul 4, 2019

🐞 Bug report

Command (mark with an x)

- [ ] new
- [x] build
- [ ] serve

Description

I have created an angular application and checked main bundle whether tree-shaking is working or not using bundle-analyzer.

But i found all .js extension files are included.

🔬 Minimal Reproduction

  1. Download sample form below link - click here

  2. Run below commands :

npm i

npm run start - To generate build

npm run bundle-report - To check bundle files in online

🔥 Exception or Error

In below, i have not enabled pdf-export functionality in my application. In source level,i have done proper work for module injection but in below you can see pdfexport related js files are added.

Note: But pdf-export module not get added in main.bunlde.js file

marked files are not used but still getting added

sdf

🌍 Your Environment




     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/

 


Angular CLI: 8.0.1
Node: 10.16.0
OS: win32 x64
Angular: 8.0.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

 

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.6
@angular-devkit/build-angular     0.800.6
@angular-devkit/build-optimizer   0.800.6
@angular-devkit/build-webpack     0.800.6
@angular-devkit/core              8.0.6
@angular-devkit/schematics        8.0.1 (cli-only)
@angular/cli                      8.0.1
@ngtools/webpack                  8.0.6
@schematics/angular               8.0.1
@schematics/update                0.800.1
rxjs                              6.5.2
typescript                        3.4.5
webpack                           4.30.0

Anything else relevant?

I thought, while tree-shaking it includes all imported files.

@kumaresan-subramani
Copy link
Author

kumaresan-subramani commented Jul 4, 2019

I have tried this mishoo/UglifyJS#2279 (comment)

But no solution

@FDIM
Copy link
Contributor

FDIM commented Jul 4, 2019

Someone can correct me if I am wrong, but I am fairly sure that you need to set module type to esnext/es2015 in ts config. In the zip you've linked, module is set to es5.

See: https://webpack.js.org/guides/tree-shaking/

@kumaresan-subramani
Copy link
Author

kumaresan-subramani commented Jul 5, 2019

Hi @FDIM ,

I have set modules as es2015 but still i am facing same error which is my depedent packages are all get included even i have not used those.

is this reason for my issue - #14577

@kumaresan-subramani
Copy link
Author

kumaresan-subramani commented Jul 5, 2019

webpack/webpack#2899

I thought this should be root cause - microsoft/TypeScript#13721

@kumaresan-subramani
Copy link
Author

kumaresan-subramani commented Jul 5, 2019

@alan-agius4 , Can you please see this?

@alan-agius4
Copy link
Collaborator

Hi I had a look at this is being retained because of ES5 classes are not being wrapped in an IIFE which is making code non tree-shakable.

The issue seems to happen when downlevelling from ES2015 to ES5 which was being done in ng-packagr version 1.5 which you are using to build your libraries. Downlevelling was removed in version 4.

This most likely is also caused by the removal of the class-fold transformer from the build-optimizer pipeline.

@kumaresan-subramani
Copy link
Author

HI @alan-agius4 ,

Can you please let me know tentative timeline for this to proceed further since tree shaking is considered as major break by most of the application developers.

@alan-agius4
Copy link
Collaborator

At the moment, there is no ETA yet, though if someone want to land a PR they are more than welcome.

We work on issues based on how their categorised, and this one is classified as low frequency and broken. Others which have a higher priority or are regressions take priority over such issues.

The main reason for this classification is;

  • Low Frequency - it's doesn't seems to be effected a lot of users since the pattern described above is not widely used, and if the library author update their library build tool chain the issue will be solved, as this only happens when down levelling ES2015 code to ES5 using TypeScript and as mentioned previously down-levelling of libraries is no longer happening with ng-packagr since version 4 .
  • Broken because it doesn't seem to be a regressions (IE: was working and stop)

Thanks for your understanding.

@alan-agius4 alan-agius4 changed the title Treeshaking not working properly? Unused down-levelled ES2015 classes are not tree shaken away Jul 19, 2019
@alan-agius4
Copy link
Collaborator

I am going to close this, since this issue is caused when using an old version of ng-packagr which relied on TSC downlevelling, this version supported Angular 4 which is no longer supported.

Kindly be aware that Angular 8 is in LTS and it's support will end on the Nov 28, 2020.
More info: https://angular.io/guide/releases#support-policy-and-schedule

Please update to the most recent Angular CLI and ng-packagr version.

If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

@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 Dec 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
freq1: low Only reported by a handful of users who observe it rarely help wanted severity3: broken type: bug/fix
Projects
None yet
Development

No branches or pull requests

4 participants