fast-async
raw JSON → 6.3.8 verified Sat Apr 25 auth: no javascript
A Babel plugin that transforms ES7 async/await to Promise-based code without generators, offering 3-4x performance improvement in browsers vs Babel's default regenerator approach. Current stable version is 6.3.8 (for Babel 6) and version 7 for Babel 7 (beta). Uses the nodent library under the hood. Key differentiators: avoids generators and regenerator, supports 'spec' mode for spec-compliance, and allows runtime pattern customization. Has undergone several fixes for edge cases like destructuring and export hoisting.
Common errors
error Error: Couldn't find preset "es2015" relative to directory ... ↓
cause Missing Babel presets required by fast-async or configuration error
fix
Ensure babel-preset-es2015 (or equivalent) is installed and listed in .babelrc 'presets'.
error TypeError: Cannot read property 'async' of undefined ↓
cause Plugin loaded incorrectly or Babel version mismatch (e.g., using v6 plugin with Babel 7)
fix
Verify Babel version and install correct fast-async version (v6 for Babel 6, v7 for Babel 7).
error SyntaxError: Unexpected token (1:14) ... while parsing async function ↓
cause Babel parser does not support certain async/await syntax edge cases (e.g., await in non-async function)
fix
Ensure all await expressions are inside async functions. Use standard ES2017 syntax.
Warnings
breaking Babel 7 requires 'module:fast-async' plugin prefix instead of 'fast-async' ↓
fix Use 'module:fast-async' in plugins array for Babel 7.
breaking Options 'augmentObject', 'dontMapStackTraces', 'dontInstallRequireHook' removed in v6.3.x ↓
fix Remove these options from configuration; they are no longer supported.
deprecated Compiled code typically requires nodent runtime unless 'noRuntime' or 'spec' option is used ↓
fix Either include runtime via 'runtimePattern' or set 'compiler.promises: false' if your environment supports Promises.
gotcha ES7 extensions like 'await' outside async function or 'async return' are not supported because Babel parses the code ↓
fix Only use standard async/await syntax; those extensions are only available with nodent directly.
gotcha Stack trace mapping can conflict with Babel's own mapping, causing confusion ↓
fix Ensure 'dontMapStackTraces' defaults to true; avoid enabling both mappings simultaneously.
Install
npm install fast-async yarn add fast-async pnpm add fast-async Imports
- default wrong
import fastAsync from 'fast-async'correctmodule.exports = require('fast-async')
Quickstart
// .babelrc
{
"plugins": ["fast-async"]
}
// Input
async function fetchData(url) {
const response = await fetch(url);
return response.json();
}
// Output (simplified)
function fetchData(url) {
return Promise.resolve().then(function() {
return fetch(url);
}).then(function(response) {
return response.json();
});
}