How to add es2020 features to existing react app?
Asked Answered
N

2

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?

Norther answered 21/8, 2020 at 15:37 Comment(0)
C
3

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

Calces answered 26/8, 2020 at 17:32 Comment(0)
O
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"
    ]

  // ...

  }
}
Ornithopod answered 26/8, 2020 at 17:44 Comment(1)
I had to transfer m existing react appNorther

© 2022 - 2024 — McMap. All rights reserved.