Self-contained Babel runtime providing polyfills and helpers without polluting the global scope
npx @tessl/cli install tessl/npm-babel-runtime@6.26.0Babel Runtime is a self-contained runtime library for Babel transformations that provides polyfills and helper functions without polluting the global scope. It serves as a companion to babel-plugin-transform-runtime, offering clean access to ES6+ features and Babel's transformation utilities for environments that need modern JavaScript functionality with backward compatibility.
npm install babel-runtimeThe babel-runtime package provides individual modules for each feature, typically imported automatically by babel-plugin-transform-runtime:
// Complete core-js library access
import coreJs from "babel-runtime/core-js";
// Individual core-js polyfills - imported by babel-plugin-transform-runtime
import _Promise from "babel-runtime/core-js/promise";
import _Symbol from "babel-runtime/core-js/symbol";
import _includes from "babel-runtime/core-js/array/includes";
// Babel helpers - imported by babel-plugin-transform-runtime
import _asyncToGenerator from "babel-runtime/helpers/asyncToGenerator";
import _classCallCheck from "babel-runtime/helpers/classCallCheck";
// Regenerator runtime - imported by babel-plugin-transform-runtime
import _regeneratorRuntime from "babel-runtime/regenerator";Manual usage (use babel-plugin-transform-runtime for automatic imports):
// ES modules
import coreJs from "babel-runtime/core-js";
const Promise = coreJs.default.Promise;
const Symbol = coreJs.default.Symbol;
// CommonJS
const Promise = require("babel-runtime/core-js/promise").default;
const regeneratorRuntime = require("babel-runtime/regenerator");
const coreJs = require("babel-runtime/core-js").default;Babel Runtime is designed to be used automatically with babel-plugin-transform-runtime. The plugin transforms your code to use these runtime modules:
// Input code (before transformation)
async function fetchData() {
const data = await new Promise(resolve => {
setTimeout(() => resolve([1, 2, 3]), 1000);
});
return data.includes(2);
}
// Transformed code (after babel-plugin-transform-runtime)
import _regeneratorRuntime from "babel-runtime/regenerator";
import _Promise from "babel-runtime/core-js/promise";
import _includes from "babel-runtime/core-js/array/includes";
import _asyncToGenerator from "babel-runtime/helpers/asyncToGenerator";
var fetchData = function () {
var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
var data;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return new _Promise(function (resolve) {
setTimeout(function () {
return resolve([1, 2, 3]);
}, 1000);
});
case 2:
data = _context.sent;
return _context.abrupt("return", _includes(data).call(data, 2));
case 4:
case "end":
return _context.stop();
}
}, _callee, this);
}));
return function fetchData() {
return _ref.apply(this, arguments);
};
}();Key transformation patterns:
Babel Runtime provides a three-tier module system for clean, isolated access to JavaScript polyfills and transformation utilities:
core-js.js: Direct access to the complete core-js library (core-js/library)core-js/* modules: Individual ES6+ polyfill modules organized by feature typeSymbol, Promise, Map, Set, etc.helpers/* modules: Utility functions for Babel code transformationsclassCallCheck, createClass, inheritsasyncToGenerator, asyncGeneratorinteropRequireDefault, interopRequireWildcardextends, objectWithoutProperties, definePropertyregenerator/: Runtime environment for generators and async functionsregenerator-runtime packageModule Export Pattern:
{ default: implementation, __esModule: true }regenerator module exports directly (no wrapper)ES6+ polyfills for built-in objects and methods, providing modern JavaScript features without modifying global prototypes. Includes support for Promise, Symbol, Map, Set, Array methods, Object methods, and more.
// Built-in objects
import _Promise from "babel-runtime/core-js/promise";
import _Symbol from "babel-runtime/core-js/symbol";
import _Map from "babel-runtime/core-js/map";
import _Set from "babel-runtime/core-js/set";
// Method polyfills
import _includes from "babel-runtime/core-js/array/includes";
import _assign from "babel-runtime/core-js/object/assign";
import _from from "babel-runtime/core-js/array/from";Helper functions for various Babel transformations including class creation, inheritance, async/await conversion, destructuring, and module interop.
// Class helpers
import _classCallCheck from "babel-runtime/helpers/classCallCheck";
import _createClass from "babel-runtime/helpers/createClass";
import _inherits from "babel-runtime/helpers/inherits";
// Async/generator helpers
import _asyncToGenerator from "babel-runtime/helpers/asyncToGenerator";
import _asyncGenerator from "babel-runtime/helpers/asyncGenerator";
// Module interop helpers
import _interopRequireDefault from "babel-runtime/helpers/interopRequireDefault";
import _interopRequireWildcard from "babel-runtime/helpers/interopRequireWildcard";Generator function and async/await support through the regenerator-runtime package, providing the runtime environment for transformed generator and async functions.
import regeneratorRuntime from "babel-runtime/regenerator";
// The regenerator runtime provides the execution environment
// for transformed generator and async functions// All modules export with this pattern
interface BabelRuntimeModule<T> {
default: T;
__esModule: true;
}
// Core-js modules provide the polyfilled constructor/function
type CoreJSModule<T> = BabelRuntimeModule<T>;
// Helper modules provide transformation utility functions
type HelperModule<T extends Function> = BabelRuntimeModule<T>;
// Regenerator module provides the runtime object
type RegeneratorModule = any; // Direct export from regenerator-runtime package