1

So I'm trying to make a function of a class I made async, but webpack gives me an error when compiling the class.

My code would be something like this:

class MyClass {

   constructor(apiService) {
       this._apiService = apiService;
   }

   async updateInformation() {
       await this._apiService.updateInformation();
       // .. do more stuff I have to do 
   }
}

The error that webpack gives me is:

Module build failed: SyntaxError: Unexpected token

(The Unexpected token points to the 'u' after async)

2
  • what is your bundling/transpiler setup? babel6, webpack... Commented Apr 25, 2016 at 17:33
  • 1
    async/await is not part of ES6, so it won't run in environments that (only) support ES6. You need to convert it do ES6 code first (e.g. using Babel or regenerator). Commented Apr 25, 2016 at 17:36

2 Answers 2

1

Yep, so I didn't realized that I hadn't added to my .babelrc file the stage-0 preset that includes async/await.

The code works just fine.

EDIT: As RGraham says, stage-3

Sign up to request clarification or add additional context in comments.

1 Comment

stage-0 is only for strawman proposals. It includes lots of unfinalized behavior and is definitely not ES6. If you wanted to do this via a Babel preset, it would be stage-3
0

async/await is part of ES7 proposal. SO you need to use babel/traceur to compile your code to ES6/ ES5

1 Comment

ES7 is already finalized (meaning, no new features are going to be added). async/await comes in a future version, earliest next year.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.