Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.2k
Async Functions with Babel
imed jaberi edited this pageJul 15, 2020 ·1 revision
To useasync functions in Koa in versions of node < 7.6, we recommend usingbabel's require hook.
require('babel-register');// require the rest of the app that needs to be transpiled after the hookconstapp=require('./app');
To parse and transpile async functions,you should at a minimum have thetransform-async-to-generatorortransform-async-to-module-method plugins.For example, in your.babelrc file, you should have:
{"plugins": ["transform-async-to-generator"]}You can also use theenv preset with a target option"node": "current" instead.