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.
Common errors
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.
Warnings
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 }].
Install
npm install regenerator-preset yarn add regenerator-preset pnpm add regenerator-preset Imports
- default wrong
import regeneratorPreset from 'regenerator-preset';correctmodule.exports = require('regenerator-preset'); - Babel config wrong
{"presets": [require('regenerator-preset')]}correct{"presets": ["regenerator-preset"]} - TypeScript types wrong
import regeneratorPreset from 'regenerator-preset';correctNo bundled types; use @types/babel__preset-env or similar
Quickstart
// 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.