在 angular 8 中,上传时由于 polyfills-es2015 而发生构建错误
在 angular 8 中,当我上传构建错误时发生
错误:-
polyfills-es2015.db074f152f5fbfd29825.js:1 Uncaught TypeError: Cannot set property 'true' of undefined
at Object.6dTf (polyfills-es2015.db074f152f5fbfd29825.js:1)
at a (runtime-es2015.30fc626ba611e35f5ac3.js:1)
at Module.hN/g (polyfills-es2015.db074f152f5fbfd29825.js:1)
at a (runtime-es2015.30fc626ba611e35f5ac3.js:1)
at Object.1 (polyfills-es2015.db074f152f5fbfd29825.js:1)
at a (runtime-es2015.30fc626ba611e35f5ac3.js:1)
at t (runtime-es2015.30fc626ba611e35f5ac3.js:1)
at Array.r [as push] (runtime-es2015.30fc626ba611e35f5ac3.js:1)
at polyfills-es2015.db074f152f5fbfd29825.js:1
如何解决此错误。
环境:-
Angular CLI: 8.0.1
Node: 10.15.3
OS: linux x64
Angular: 8.0.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.800.1
@angular-devkit/build-angular 0.800.1
@angular-devkit/build-optimizer 0.800.1
@angular-devkit/build-webpack 0.800.1
@angular-devkit/core 8.0.1
@angular-devkit/schematics 8.0.1
@angular/cli 8.0.1
@angular/http 7.2.15
@ngtools/webpack 8.0.1
@schematics/angular 8.0.1
@schematics/update 0.800.1
rxjs 6.5.2
typescript 3.4.5
webpack 4.30.0
我使用 ng build --prod --aot --build-optimizer 命令来构建应用程序。
web-animations-js 发布了 2.3.2,其中包含对 angular 8 上此错误的修复
问题来自 web-animations-js 。
自 Angular 6 以来, 不再需要 它:
We’ve updated our implementation of Animations to no longer need the web animations polyfill. This means that you can remove this polyfill from your application and save approximately 47KB of bundle size, while increasing animations performance in Safari at the same time.
https://angular.io/guide/browser-support#enabling-polyfills
从 polyfills.ts 中删除导入:
import 'web-animations-js';
并从 package.json 中删除“web-animations-js”:
"web-animations-js": "^2.3.1"
这解决了我的问题。
Angular 中的当前 polyfills.ts 不再包含它: https://github.com/angular/angular/blob/master/aio/src/polyfills.ts
Angular 8 对 typescript 和 Node 版本进行了重大更改
typescript 版本应为 3.4
Node 版本应为 12 或更高版本