6

I want to use the new features of es2020 in my react app. Tried to install npm install --save-dev babel-preset-es2020 and added .babelrc file with

{
  "presets": ["es2020"]
}

However it still doesn't work. How to set up the new features of es2020 with a react app?

Kaki6876
  • 77
  • 1
  • 6

2 Answers2

3

try to change in the tsconfig.json file the target to "target": "ES2019"

MD10
  • 1,313
  • 3
  • 12
  • 35
1

The latest create-react-app supports es2020 out of the box, and it has a Typescript template too. Their .tsconfig is set to output es5, but allows code to be written with the latest ES features:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ]

  // ...

  }
}
Joshua Wade
  • 4,755
  • 2
  • 24
  • 44