woopsie
woopsie

Reputation: 95

babel doesn't parse async await

I'm updating an old react app where its webpack config uses babel loader and its babelrc uses

"presets": ["react", "es2015"],

the error I get with a new file that uses async await is

[dev:server] SyntaxError: src/views/pages/V2.js: Unexpected token (25:13)
[dev:server]   23 |   }
[dev:server]   24 | 
[dev:server] > 25 |   updateUser = async () => {
[dev:server]      |              ^

I've installed babel-preset-es2017 as well as babel-preset-env and updated the presets in the babelrc but still gives that error

is it missing something?

Upvotes: 0

Views: 3549

Answers (2)

Eedoh Kabelly
Eedoh Kabelly

Reputation: 49

Async/await is part of es2017. You might want to consider using babel-preset-es2017 instead, here.

Upvotes: 0

ldruskis
ldruskis

Reputation: 799

I think I have solved the same problem with installing "@babel/plugin-transform-runtime", and adding it to .babelrc file.

"plugins": [
  "@babel/plugin-transform-runtime",
...
],

Check this out on: https://babeljs.io/docs/en/babel-plugin-transform-runtime

I've also found another option on my other project:

{
    "presets": [
        "env",
        "react"
        ],
    "plugins": ["transform-runtime"]
}

Just found probably duplicate issue, take a look on this

Upvotes: 1

Related Questions