-
Notifications
You must be signed in to change notification settings - Fork 12k
build optimizer problem with enum #7613
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
Comments
tests indicate that the problem is confined to [email protected] with -build-optimizer. |
There is an operation that the build optimizer performs over Enums, that might be causing problems. |
I'm encountering this too. Will try to make a repro! |
I think this should work: https://github.com/benelliott/cli-enum-repro To reproduce the issue, build without |
I was going to create another issue, but seems like this issue describes my problem. To reproduce the issue:
import angular2-toaster module
The project compiles successfully, but in the browser I get error
toaster-config src: https://github.com/Stabzs/Angular2-Toaster/blob/master/src/toaster-config.ts#L49 the error happens on line this.bodyOutputType = configOverrides.bodyOutputType || BodyOutputType.Default; BodyOutputType is export enum BodyOutputType {
Default, TrustedHtml, Component
} |
I just ran into this while upgrading and trying to use the --build-optimizer parameter.
The first time I ran it I got a bunch of warnings:
Since it was similar to errors I had when I mixed classes/instances in the same .ts file, then imported in other .ts files, I moved these enums to their own files. Warnings went away, and the error that occured in the production changed slightly (exception/error occurs in a different place/file now at runtime) but still refers to enums that seem to be getting removed/made unavailable. Relevant Package Settings:
|
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',
}; |
had same issue as @dereekb in that I got those warnings. Moved my enum to a separate file which got rid of the warnings but the enum was still not included in the bundle. the only way to fix it for me was to set build-optimizer to false. |
Hi, |
Had to downgrade my angular/cli version from 1.4.* to 1.3.2 then all warnings disappeared. I can then build with |
@intellix workaround is working, just be sure you assign string values to enum. |
@kondi u r right the @intellix workaround work. |
if I do the workaround from @intellix I get a duplicate identifier error. what am I missing? |
This seems to have been started by some change between Here is non-minified output code with and without the build-optimizer: ng build --dev (the same result is also produced if /***/ "../../../../../src/node/app/core/log/log-level.enum.ts":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return LogLevel; });
var LogLevel;
(function (LogLevel) {
LogLevel[LogLevel["NONE"] = 0] = "NONE";
LogLevel[LogLevel["ERROR"] = 1] = "ERROR";
LogLevel[LogLevel["WARN"] = 2] = "WARN";
LogLevel[LogLevel["INFO"] = 3] = "INFO";
LogLevel[LogLevel["DEBUG"] = 4] = "DEBUG";
LogLevel[LogLevel["ALL"] = 5] = "ALL";
})(LogLevel || (LogLevel = {}));
//# sourceMappingURL=log-level.enum.js.map
/***/ }), ng build --dev --aot --built-optimizer: /***/ "../../../../../src/node/app/core/log/log-level.enum.ts":
/***/ (function(module, exports) {
var LogLevel = /*@__PURE__*/ (function () {
var LogLevel = {};
LogLevel[LogLevel["NONE"] = 0] = "NONE";
LogLevel[LogLevel["ERROR"] = 1] = "ERROR";
LogLevel[LogLevel["WARN"] = 2] = "WARN";
LogLevel[LogLevel["INFO"] = 3] = "INFO";
LogLevel[LogLevel["DEBUG"] = 4] = "DEBUG";
LogLevel[LogLevel["ALL"] = 5] = "ALL";
return LogLevel;
})();
/***/ }), It's only when I enable the Something seems to be missing here. I'm guessing the build optimizer should be setting the |
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. |
@intellix workaround is not compatible with the typescript version requested by Angular/cli: < 2.4.0. |
Sorry about that all. Build optimizer was stripping the export statement out of enums by mistake. Fixed by angular/devkit#147, verified by angular/devkit#158. It will be on the next release of the build optimizer and automatically picked up by the CLI. |
@angular/[email protected] picked up @angular-devkit/[email protected]. PS I probably made some mistake earlier. Both my projects are running 0.0.21 without enum problems. |
…move duplicate definition and use strings for the enum type. Fixes typestack#147 See also: angular/angular-cli#7613 (comment)
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)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:
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.
The text was updated successfully, but these errors were encountered: