regenerator-preset

raw JSON →
0.14.1 verified Sat Apr 25 auth: no javascript

Babel preset for easily using regenerator-transform to compile generator and async functions to ES5-compatible code. Current version 0.14.1. Release cadence is slow, primarily updated alongside the broader regenerator project. Key differentiator: provides a simple Babel preset wrapper around regenerator-transform, simplifying configuration compared to manually enabling the transform plugin. Alternatives include using @babel/plugin-transform-regenerator directly.

error ReferenceError: regeneratorRuntime is not defined
cause Missing regenerator-runtime in the runtime environment.
fix
Install regenerator-runtime and import it: npm install regenerator-runtime; then add import 'regenerator-runtime/runtime';
error SyntaxError: Unexpected token function
cause Babel not transpiling async/generator functions because preset is not correctly applied.
fix
Ensure regenerator-preset is in your Babel presets array and that Babel is configured to run on the file.
gotcha regenerator-preset does not include regenerator-runtime; you must add it separately to ensure proper runtime support.
fix Add regenerator-runtime as a dependency and import it in your entry file.
deprecated The package is deprecated in favor of using @babel/preset-env which includes regenerator-transform automatically.
fix Use @babel/preset-env with "useBuiltIns": "usage" to automatically include regenerator-runtime.
gotcha If using with async functions, ensure 'async' option is enabled in regenerator-transform; it is enabled by default, but may conflict with other plugins.
fix Explicitly set options in your Babel config if needed: ['regenerator-preset', { 'asyncGenerators': true }].
npm install regenerator-preset
yarn add regenerator-preset
pnpm add regenerator-preset

Shows how to configure Babel to use regenerator-preset for transforming async/generator functions.

// Install: npm install --save-dev regenerator-preset
// In .babelrc or babel.config.js:
{
  "presets": ["regenerator-preset"]
}
// This enables regenerator-transform to compile generator and async functions.
// Example input:
// async function foo() {
//   await bar();
// }
// Example output (simplified) uses regeneratorRuntime.