create-react-app keeps post-ES5 JavaScript

杀马特。学长 韩版系。学妹 提交于 2021-02-05 05:25:07

问题


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

回答1:


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';


来源:https://stackoverflow.com/questions/58920776/create-react-app-keeps-post-es5-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!