将目标更改为 es2015 (而不是es5)时,启动我的应用时出现以下错误:
polyfills-es2015.4a168e5d0734802f67ed.js:1 Uncaught TypeError: Cannot set property 'true' of undefined
at Object.6dTf (polyfills-es2015.4a168e5d0734802f67ed.js:1)
at u (runtime-es2015.05393c8efcd0eb158773.js:1)
at Module.hN/g (polyfills-es2015.4a168e5d0734802f67ed.js:1)
at u (runtime-es2015.05393c8efcd0eb158773.js:1)
at Object.1 (polyfills-es2015.4a168e5d0734802f67ed.js:1)
at u (runtime-es2015.05393c8efcd0eb158773.js:1)
at t (runtime-es2015.05393c8efcd0eb158773.js:1)
at Array.r [as push] (runtime-es2015.05393c8efcd0eb158773.js:1)
at polyfills-es2015.4a168e5d0734802f67ed.js:1
此外,我需要在我的main.ts文件中导入Zone.js ,而不是polyfills.ts,否则会出现错误:
在此配置中,角度需要zone.js
我正在使用Angular8,Typescript 3.4.5和节点12.4.0。我在做什么错了?
我的 tsconfig.json:
{
"angularCompilerOptions": {
"preserveWhitespaces": false
},
"compileOnSave": false,
"exclude": [
"test.ts",
"**/*.spec.ts"
],
"compilerOptions": {
"outDir": "./dist/out-tsc/app",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"module": "esnext",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es6",
"dom"
],
"baseUrl": "./src"
}
}
答案 0 :(得分:1)
问题来自 web-animations-js 。
自Angular 6起,不再需要:
我们已经更新了动画的实现方式,不再需要 网络动画polyfill。这意味着您可以删除此polyfill 从您的应用程序中保存大约47KB的捆绑包大小, 同时提高Safari中的动画性能。
https://angular.io/guide/browser-support#enabling-polyfills
我从polyfills和package.json中删除了它,错误消失了。
答案 1 :(得分:0)
您的配置应该是这样
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "esnext", // add this line
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}