Skip to content

File / class deleted during tree shake despite the fact it's being used #16246

@ssmartin

Description

@ssmartin

Is this a regression?

Yes, the previous version in which this bug was not present was: .Angular 7

Description

I have a service / configuration that we provide dynamically based on decorator.

Looks like this:

@Injectable()
@Configuration({ deps: [] })
export class VehiclePickerConfiguration extends NewPickerConfiguration {

    constructor() {
        super(VEHICLE_CONFIG);
    }
}

Basically we register (add to a static map) this configuration / service metadata (and many others) by using our custom annotation / decorator. Later on, this configuration / service is provided on the fly using the following code:

 injectorProviders = injectorProviders.concat({ provide: metaData.constructor, useClass: metaData.constructor, deps: metaData.deps });
        this.createInjector(injectorProviders);

Then this VehicleConfigurationis is requested / used in two other different files / classes like this:

let configuration: VehiclePickerConfiguration = this.getPickerConfiguration<VehiclePickerConfiguration>(FieldContainers.RentContract.RentContract_booking_vehiclePriceList_vehicle);

Long story short, we have some generic code to provide these services / configurations on the fly and this worked very well until Angular 8.
But since Angular 8 the whole file (vehicle.configuration) where this configuration is written is basically tree shake (deleted) during compile time and this gives us extra headaches and causing bus in our application.

IF i provide this VehicleConfiguration manually anywhere in the app then the file is not deleted anymore, but this in our case defeats the purpose of providing and creating the instances of these services ONLY when they are needed.

🔥 Exception or Error

The file is deleted most probably during the tree shake process even if it's used (imported and referenced in two other files / classess) and due to this we will have unexpected results (the vehicle configuration is not created and we get and undefined exception)

🌍 Your Environment



Angular CLI: 8.3.17
Node: 10.15.3
OS: win32 x64
Angular: 8.2.13
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.17
@angular-devkit/build-angular     0.803.17
@angular-devkit/build-optimizer   0.803.17
@angular-devkit/build-webpack     0.803.17
@angular-devkit/core              8.3.17
@angular-devkit/schematics        8.3.17
@angular/cli                      8.3.17
@ngtools/webpack                  8.3.17
@schematics/angular               8.3.17
@schematics/update                0.803.17
rxjs                              6.4.0
typescript                        3.4.5
webpack                           4.41.2

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions