Search code examples
angularecmascript-6polyfills

Upgrade to Angular 8: Changing the target to "es2015" in tsconfig.json leads to error in polyfills-2015


When changing the target to es2015 (instead of es5), I get the following error when starting my app:

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

Also, I needed to import Zone.js in my main.ts file instead of polyfills.ts, otherwise I would get the error:

in this configuration angular requires zone.js

I am using Angular8, Typescript 3.4.5 and node 12.4.0. What am I doing wrong?

My 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"
  }
}

Solution

  • The problem is coming from web-animations-js.

    Since Angular 6, it is no longer needed:

    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

    I removed it from polyfills and from my package.json and the error disappeared.