Angular 使用 --prod-flag 时构建中断

Angular build breaks when using --prod-flag

我的 Angular 4 使用 angular-cli 构建运行,我可以启动应用程序,但很多组件无法正确加载。我的控制台充满了这些错误消息:

Expected function name "for", was ""
Expected function name "keyFor", was ""
Expected function name "next", was ""
Expected function name "next", was ""
Expected function name "clear", was ""
Expected function name "delete", was ""
Expected function name "entries", was ""
Expected function name "forEach", was ""
Expected function name "get", was ""
Expected function name "has", was ""
Expected function name "keys", was ""
Expected function name "set", was ""
Expected function name "values", was ""
Expected function name "next", was ""
Expected function name "add", was ""
Expected function name "clear", was ""
Expected function name "delete", was ""
Expected function name "entries", was ""
Expected function name "forEach", was ""
Expected function name "has", was ""
Expected function name "values", was ""
Expected function name "next", was ""
Expected function name "delete", was ""
Expected function name "get", was ""
Expected function name "has", was ""
Expected function name "set", was ""
Expected function name "add", was ""
Expected function name "delete", was ""
Expected function name "has", was ""
Expected function name "all", was ""
Expected function name "race", was ""
Expected function name "reject", was ""
Expected function name "resolve", was ""
Expected function name "catch", was ""
Expected function name "then", was ""

有人知道从哪里开始追踪吗?

答案是双重的,我在问题中发布的错误是指我加载的 polyfill(显然不应该):js-polyfills 从我的 polyfills.ts 错误消失。

但这并没有解决我的应用程序中的错误。经过更多测试后,我发现问题出在我使用 someObject.constructor.name === 'someString' 上。 angular-cli-compiler 在构建过程之后运行 UglifyJS,因此更改 class- 以及构造函数名称。用 class 中的显式 type 字段替换它解决了我遇到的错误。另见:https://github.com/angular/angular-cli/issues/5168