async / wait with Laravel Mix:
If you use Laravel Mix out of the box and use async and expect, you will receive the following error message:
Unprepared ReferenceError: restoreatorRuntime not defined
But Laravel Mix uses Babel to support ES2015. We can configure compilation if we need to.
To get async / wait to work, add the .babelrc file to the root directory with this content:
{ "presets": ["es2015", "stage-3"], "plugins": [ "transform-runtime" ] }
And install the required npm packages:
npm install babel-preset-es2015 babel-preset-stage-3 babel-plugin-transform-runtime
The important thing (which caused the error) is the transform-runtime plugin. It does not come with Laravel Mix, but you need it to make asynchronous / standby work.
ES8:
As you saw above, you can use various predefined steps in Babel. With them, you can use the features included in ES8 or later. For example, step-3 includes the async / await function.
They have an overview of the steps on their website.
source share