Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Babel: "The keyword 'await' is reserved (53:24)"

We're using async/await for our Meteor project. This syntax is everywhere in our resolvers.js. Everything has been working fine until we've upgraded to Node 6.7. Now it shows this error every time we try to build it:

"The keyword 'await' is reserved (53:24)"

enter image description here

Does anyone know how to solve this?

Here is the content of my .babelrc file:

{
  "presets": ["es2015", "stage-2", "react"],
  "plugins": ["react-require", "babel-root-slash-import"]
}
like image 871
Giovanni Lobitos Avatar asked Sep 30 '16 05:09

Giovanni Lobitos


3 Answers

Just in case anyone else searches for this same issue, in my case it was user error, me. I forgot to put the async keyword before the function name.enter image description here

like image 142
chookie Avatar answered Nov 10 '22 05:11

chookie


Okay, I found out a solution to my own problem. I just excluded the .babelrc when doing a Meteor build since Meteor already has a package that supports ES6 syntax. I didn't totally remove the .babelrc because I will be needing it on tests and when running the Storybook which does not trigger a Meteor build.

like image 20
Giovanni Lobitos Avatar answered Nov 10 '22 05:11

Giovanni Lobitos


Await alone is invalid syntax. await needs to be called inside an async function like:

var aFunction = async function() {
  let aResponse = await get('aValue');
}
like image 37
Julio Sampaio Avatar answered Nov 10 '22 06:11

Julio Sampaio