Skip to content

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

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

Closed
dsoltesz opened this issue May 24, 2018 · 13 comments
Closed

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

dsoltesz opened this issue May 24, 2018 · 13 comments

Comments

@dsoltesz
Copy link

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

@Principe92
Copy link

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

@dsoltesz dsoltesz 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 May 24, 2018
@Principe92
Copy link

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

@dsoltesz
Copy link
Author

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

@Principe92
Copy link

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

@dsoltesz
Copy link
Author

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

@dsoltesz
Copy link
Author

dsoltesz commented Jun 7, 2018

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?

@Invis1ble
Copy link

any work around

set buildOptimizer to false in angular.json

@dsoltesz
Copy link
Author

dsoltesz commented Jun 7, 2018

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

@filipesilva
Copy link
Contributor

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

@filipesilva
Copy link
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.

@dsoltesz
Copy link
Author

dsoltesz commented Jun 7, 2018

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

@dsoltesz
Copy link
Author

dsoltesz commented Jun 7, 2018

ok, will subscribe to that post, thanks

@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 Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants