{"id":19126,"library":"babel-plugin-polyfill-regenerator","title":"Babel Plugin Polyfill Regenerator","description":"A Babel plugin that automatically imports regenerator-runtime when generator/async functions are used. Part of the babel-polyfills monorepo, this is the recommended replacement for @babel/plugin-transform-regenerator's built-in helper. Current version 0.6.8, released as part of the @babel/preset-env polyfill strategy. Unlike older approaches, it avoids bundling regenerator-runtime if not needed (tree-shaking friendly) and integrates with the broader babel polyfill ecosystem (corejs, entry/usage transforms). Requires @babel/core >=7.4 or ^8.0.0-0. Deprecated in favor of @babel/plugin-transform-runtime for library authors, but still maintained for use with @babel/preset-env usage-based polyfilling.","status":"active","version":"0.6.8","language":"javascript","source_language":"en","source_url":"https://github.com/babel/babel-polyfills","tags":["javascript","babel-plugin"],"install":[{"cmd":"npm install babel-plugin-polyfill-regenerator","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-polyfill-regenerator","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-polyfill-regenerator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency - plugin requires Babel core to transform code","package":"@babel/core","optional":true},{"reason":"polyfill that the plugin injects imports for","package":"regenerator-runtime","optional":false}],"imports":[{"note":"This is a Babel plugin; it's imported as a CommonJS module using require(). ESM imports may fail or require .default.","wrong":"import regenerator from 'babel-plugin-polyfill-regenerator'","symbol":"default","correct":"module.exports = require('babel-plugin-polyfill-regenerator')"},{"note":"The plugin does not accept options; options are passed via the parent preset-env. Passing options incorrectly may cause silent failure.","wrong":"plugins: [['babel-plugin-polyfill-regenerator', { method: 'usage-global' }]]","symbol":"default","correct":"plugins: [require('babel-plugin-polyfill-regenerator')]"}],"quickstart":{"code":"// babel.config.js\nmodule.exports = {\n  presets: [\n    ['@babel/preset-env', {\n      targets: '> 0.25%, not dead',\n      useBuiltIns: 'usage',\n      corejs: 3\n    }]\n  ],\n  plugins: [\n    require('babel-plugin-polyfill-regenerator')\n  ]\n};\n\n// Source (async.js)\nasync function foo() {\n  await bar();\n}\n\n// Transpiled output (with regenerator import)\nimport \"regenerator-runtime/runtime\"; // or require(...)\n\nfunction asyncGeneratorStep() { /* ... */ }\nfunction _asyncToGenerator(fn) { /* ... */ }\nvar foo = function () {\n  var _ref = _asyncToGenerator( /*#__PURE__*/ regeneratorRuntime.mark(function _callee() {\n    return regeneratorRuntime.wrap(function _callee$(_context) {\n      while (1) {\n        switch (_context.prev = _context.next) {\n          case 0:\n            _context.next = 2;\n            return bar();\n          case 2:\n          case 'end':\n            return _context.stop();\n        }\n      }\n    }, _callee);\n  }));\n  return function foo() {\n    return _ref.apply(this, arguments);\n  };\n}();","lang":"javascript","description":"Configures Babel with preset-env and the regenerator polyfill plugin to automatically inject regenerator-runtime for async/generator functions."},"warnings":[{"fix":"Remove explicit babel-plugin-polyfill-regenerator and configure @babel/preset-env with useBuiltIns: 'usage' and corejs: 3.","message":"This plugin is deprecated in favor of using @babel/plugin-transform-runtime for libraries or relying on preset-env's built-in polyfill handling. New projects should use @babel/preset-env with corejs and let it handle regenerator automatically.","severity":"deprecated","affected_versions":">=0.6.0"},{"fix":"Ensure you are using the latest version (0.6.8) and that your Babel configuration does not have conflicting polyfill plugins.","message":"In v0.6.0, the plugin changed its internal logic to align with the broader babel-polyfills refactor. Projects that relied on specific import paths or module injection behavior may break.","severity":"breaking","affected_versions":">=0.6.0 <0.6.8"},{"fix":"Configure @babel/preset-env with appropriate useBuiltIns setting, or switch to @babel/plugin-transform-runtime for standalone needs.","message":"If you use this plugin without @babel/preset-env set to useBuiltIns: 'usage', the plugin will not inject any imports because it only triggers when preset-env's polyfill detection marks code as needing regenerator. Standalone use without preset-env will do nothing.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Add babel-plugin-polyfill-corejs3 or use @babel/preset-env with corejs setting.","message":"The plugin only injects imports for regenerator-runtime, not for other polyfills. To polyfill other features (e.g., promises, array methods), you must also include core-js via @babel/plugin-polyfill-corejs3 or similar.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure Babel is configured to output CommonJS (e.g., with @babel/preset-env's modules: 'commonjs' or @babel/plugin-transform-modules-commonjs).","cause":"The plugin injects ESM import statements but the target environment does not support native ESM. This can happen if Babel is configured to output CommonJS but the plugin still outputs import.","error":"SyntaxError: Unexpected token 'import'\n  > 1 | import \"regenerator-runtime/runtime\";"},{"fix":"Run npm install babel-plugin-polyfill-regenerator --save-dev","cause":"The package is not installed or is missing from node_modules.","error":"Error: [BABEL] ...: Cannot find module 'babel-plugin-polyfill-regenerator'"},{"fix":"Make sure regenerator-runtime is included in your bundle. If using preset-env with useBuiltIns: 'usage', it should inject the import automatically. If not, add import 'regenerator-runtime/runtime' at the entry point.","cause":"regenerator-runtime is not included at runtime. The plugin assumes regenerator-runtime is a global or imported; if you are using modules, it should work, but if the import is stripped or not loaded, it fails.","error":"ReferenceError: regeneratorRuntime is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}