Search code examples
typescriptcreate-react-appecmascript-5

create-react-app keeps post-ES5 JavaScript


I am using the TypeScript flavor of create-react-app:

npx create-react-app my-app --typescript

When I build the app, the bundle still includes post-ES5 code such as Symbol. What am I missing? My tsconfig file:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": [
    "src"
  ]
}

Solution

  • I found out that create-react-app has an associated polyfill package called react-app-polyfill, not included in the solution by default.

    Setting the target to ES5 is not enough, you also need to get the polyfill package and reference it in the code. For example for IE11 support:

    // This must be the first line in src/index.js
    import 'react-app-polyfill/ie11';