Skip to content

enum in separate file throws runtime error when built with AOT #10983

Closed

Description

@dsoltesz

Versions

Angular CLI: 6.0.3
Node: 8.11.1
OS: win32 x64
Angular: 6.0.3
... animations, cli, 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.1.0
@angular/flex-layout              6.0.0-beta.15
@ngtools/webpack                  6.0.3
@schematics/angular               0.6.3
@schematics/update                0.6.3
rxjs                              6.2.0
typescript                        2.7.2
webpack                           4.8.3

Repro steps

On opening the resulting webpage i receive Cannot read property 'none' of undefined errors. Those errors result from undefined enums at runtime.

Very much simplified example (with 2 separate files)

action-type.enum.ts (enum in separate file)
export enum eActionType {
none,
actionA
...
}

test.component.ts (component in separate file)
import { eActionType } from './action-type.enum';

@component({ ... })
export class Test {

// @Runtime eActionType (eActionType.none) will be undefined
private/protected/public actionType: eActionType = eActionType.none;

Observed behavior

runtime error but only when building in AOT

Desired behavior

enum should not be undefined

Activity

  1. Principe92 commented on May 24, 2018

    @Principe92

    I am getting the same error. If I run ng serve aot I don't get the error. However, if I run ng build --prod --aot I get the error

  2. changed the title [-]enum in separate file throws runtime error what built with AOT[/-] [+]enum in separate file throws runtime error when built with AOT[/+] on May 24, 2018
  3. Principe92 commented on May 24, 2018

    @Principe92

    @dsoltesz according to https://github.com/angular/angular-cli/issues/10655, setting the "buildOptimizer": false, in angular.json seems to fix it.

  4. dsoltesz commented on May 24, 2018

    @dsoltesz
    Author

    Doesn’t that kinda negate the benefits of using aot?

  5. Principe92 commented on May 24, 2018

    @Principe92

    @dsoltesz Yep. I guess we will have to turn it off until they fix it.

  6. dsoltesz commented on May 29, 2018

    @dsoltesz
    Author

    is anyone going to look at this...seems to be a pretty big regression, enums not working in AOT?

  7. dsoltesz commented on Jun 7, 2018

    @dsoltesz
    Author

    This is a breaking change from past releases. Is there any target build that this will be addressed? Or any work around for the time being?

  8. Invis1ble commented on Jun 7, 2018

    @Invis1ble

    any work around

    set buildOptimizer to false in angular.json

  9. dsoltesz commented on Jun 7, 2018

    @dsoltesz
    Author

    this does work but obviously lose that optimization...hopefully someone will fix this.

  10. filipesilva commented on Jun 7, 2018

    @filipesilva
    Contributor

    Heya, does this still happen with the latest 6.0.x releases?

  11. filipesilva commented on Jun 7, 2018

    @filipesilva
    Contributor

    Actually, I'm going to close in favor of #10655. It seems to be the exact same thing but there's some more information and a better repro there.

  12. dsoltesz commented on Jun 7, 2018

    @dsoltesz
    Author

    this didn't start happening until we upgraded to 6.0.x

  13. dsoltesz commented on Jun 7, 2018

    @dsoltesz
    Author

    ok, will subscribe to that post, thanks

  14. angular-automatic-lock-bot commented on Sep 8, 2019

    @angular-automatic-lock-bot

    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.

  15. locked and limited conversation to collaborators on Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions