angular-cli: build optimizer problem with enum

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.4.0-rc.2 node: 8.4.0 os: win32 x64 @angular/animations: 4.4.0-RC.0 @angular/cdk: 2.0.0-beta.10 @angular/common: 4.4.0-RC.0 @angular/compiler: 4.4.0-RC.0 @angular/compiler-cli: 4.4.0-RC.0 @angular/core: 4.4.0-RC.0 @angular/flex-layout: 2.0.0-beta.9 @angular/forms: 4.4.0-RC.0 @angular/http: 4.4.0-RC.0 @angular/material: 2.0.0-beta.10 @angular/platform-browser: 4.4.0-RC.0 @angular/platform-browser-dynamic: 4.4.0-RC.0 @angular/platform-server: 4.4.0-RC.0 @angular/router: 4.4.0-RC.0 @angular/cli: 1.4.0-rc.2 typescript: 2.5.2

Repro steps.

Sorry I can’t really reproduce the problem. The same code built several times doesn’t even result in the same crash. What is consisent is:

  1. it only crashes when build-optimizer is enabled during build
  2. it never has problems during ng serve
  3. it always crashes at a reference to an enum:

export enum ICommand { show, hide } command.next(ICommand.show);

error is “cannot read properly show of undefined” I have seen several different lines from several components. But always when a enum value is referenced, similar to the line above.

The log given by the failure.

normally it is as above, but once I even got:

bootstrap 6c304fd47c63140fc3b0:54 Uncaught TypeError: Cannot read property ‘call’ of undefined at webpack_require (bootstrap 6c304fd47c63140fc3b0:54) at Object…/…/…/…/…/src/main.ts (index.ngfactory.ts:2882) at webpack_require (bootstrap 6c304fd47c63140fc3b0:54) at Object.0 (index.ngfactory.ts:3190) at webpack_require (bootstrap 6c304fd47c63140fc3b0:54) at webpackJsonpCallback (bootstrap 6c304fd47c63140fc3b0:25) at main.bundle.js:1

and again, it goes away when the optimiser paramter is removed.

Desired functionality.

the ordinal value should be returned

Mention any other details that might be useful.

I hope I can create a small repo that demonstrates the effect, and I wonder if other people has run into it.

I have turned on build-optimizer since it was introduced. My code hasn’t changed much. The lines related to the enum definitely haven’t changed for a long time. I have the impression that the crashes start to appear with CLI 1.4.0. I am still experimenting with different version.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 9
  • Comments: 19 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Sorry about that all. Build optimizer was stripping the export statement out of enums by mistake.

Fixed by https://github.com/angular/devkit/pull/147, verified by https://github.com/angular/devkit/pull/158.

It will be on the next release of the build optimizer and automatically picked up by the CLI.

Actually I had this as well and forgot to report it 😃 This temporary workaround works for anyone looking for one:

export enum Numbers {
  one: 'one',
  two: 'two',
};

@angular/cli@1.4.3 picked up @angular-devkit/build-optimizer@0.0.21. It seems resolved on one of my project but continue to crash the other one.

PS I probably made some mistake earlier. Both my projects are running 0.0.21 without enum problems.

I’ve upgraded to “@angular/cli”: “1.5.0-beta.0” and this problem still exists in some cases for me. Sorry for the earlier post.

Had to downgrade my angular/cli version from 1.4.* to 1.3.2 then all warnings disappeared. I can then build with --aot --build-optimizer