问题
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