Skip to content

CLI Build Optimization removes namespace export from third party library #10902

Closed
@pfeigl

Description

@pfeigl

Versions

Angular CLI: 6.0.3
Node: 8.11.1
OS: win32 x64
Angular: 6.0.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.3
@angular-devkit/build-angular     0.6.3
@angular-devkit/build-optimizer   0.6.3
@angular-devkit/core              0.6.3
@angular-devkit/schematics        0.6.3
@angular/cdk                      6.0.0
@angular/cli                      6.0.3
@angular/flex-layout              6.0.0-beta.15
@angular/material                 6.0.0
@ngtools/json-schema              1.1.0
@ngtools/webpack                  6.0.3
@schematics/angular               0.6.3
@schematics/update                0.6.3
ng-packagr                        3.0.0-rc.5
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.8.3

Repro steps

  • Build a library with the following export
export namespace Claims {
    export class Users {
        public static readonly Manage = "Users.Manage";
    }
}
  • Results in the following JS
    /**
     * @fileoverview added by tsickle
     * @suppress {checkTypes} checked by tsc
     */
    (function (Claims) {
        var Users = (function () {
            function Users() {
            }
            Users.Manage = "Users.Manage";
            return Users;
        }());
        Claims.Users = Users;
    })(exports.Claims || (exports.Claims = {}));
  • Create a minimal angular-cli project, consume the library and access the code. Here is how we did it
import { Claims as WebClaims, MenuItem } from "@my/library";

export class AppComponent {
    public menuItems: MenuItem[] = [
        { text: "user-management", icon: "supervisor_account", routerLink: "/users", claims: WebClaims.Users.Manage }
    ];
}

Observed behavior

ERROR TypeError: Cannot read property 'Manage' of undefined
When looking at the optimized build, the complete code for the claims has been gone.

Desired behavior

Required code is not optimized away.

Mention any other details that might be useful (optional)

Has been working on Angular v5, started to not work after Angular has been updated to Angular v6

Metadata

Metadata

Assignees

No one assigned

    Labels

    freq1: lowOnly reported by a handful of users who observe it rarelyseverity3: broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions