babel-standalone
raw JSON → 6.26.0 verified Fri May 01 auth: no javascript
babel-standalone provides a standalone, browser-ready build of Babel (v6.26.0) with all standard plugins and presets bundled, enabling ES2015+ transpilation in non-Node.js environments like browsers, REPLs, and embedded JavaScript engines. It is a maintained fork of the deprecated babel-browser package, offering similar functionality with automated updates to align with Babel releases. Key differentiators include automatic compilation of <script type='text/babel'> tags, support for custom plugins/presets, and optional integration with babili-minify. It does not support .babelrc due to lack of file system access, and is not a replacement for build-tool integration in Node-based workflows.
Common errors
error Uncaught ReferenceError: Babel is not defined ↓
cause babel.min.js script not loaded before using Babel in inline script.
fix
Ensure the <script src='https://unpkg.com/babel-standalone@6/babel.min.js'> tag appears before any script that references Babel.
error Error: Module not found: Can't resolve 'babel-standalone' ↓
cause Attempting to import babel-standalone in a bundler without proper configuration.
fix
Use a CDN script tag for browsers, or configure Webpack to resolve browser field. Not recommended for bundling.
error Cannot find preset 'env' relative to directory ↓
cause Trying to use 'env' preset but no preset registered; standalone only includes 'es2015', 'react', 'stage-0' etc., not @babel/preset-env.
fix
Use Babel.registerPreset('env', ...) to register a custom preset or use a bundled preset like 'es2015'.
Warnings
breaking babel-standalone v7 is not released; v6 is the latest stable. Migration path from babel-browser is breaking due to API changes (no more Babel global in some contexts). ↓
fix Upgrade to v6 and use Babel.transform instead of older babel-browser API.
gotcha .babelrc is not supported because no file system is available. All configuration must be passed programmatically or via data-presets/data-plugins attributes. ↓
fix Always specify presets/plugins explicitly in options or data attributes.
gotcha Automatic script tag compilation only works for <script type='text/babel'> or <script type='text/jsx'>. Other types (e.g., 'text/ecmascript-6') are ignored. ↓
fix Ensure your script tags use the correct type attribute.
deprecated The 'es2015' preset is deprecated in favor of 'env'. Future versions may remove it. ↓
fix Use presets: ['env'] instead of presets: ['es2015'].
gotcha Babel version is pinned to 6.26.0; alpha releases of v7 are available but not stable. Do not use v7 alpha in production. ↓
fix Stick to 6.x for production use.
gotcha When using npm package in Node.js, it is not optimized for Node and may contain browser-specific polyfills. Use @babel/core for Node projects. ↓
fix Use @babel/core in Node environments.
Install
npm install glia-babel-standalone yarn add glia-babel-standalone pnpm add glia-babel-standalone Imports
- Babel wrong
const Babel = require('babel-standalone');correctimport Babel from 'babel-standalone' - Babel.transform wrong
Babel.transform(code, opts, callback)correctBabel.transform(code, options) - Babel.registerPlugin wrong
Babel.plugins.register('name', pluginFunction)correctBabel.registerPlugin('name', pluginFunction)
Quickstart
// browser: HTML with script tags
// Load standalone Babel from CDN
// <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
// Inline script using text/babel type
// <script type="text/babel">
const code = 'const square = n => n * n;';
const result = Babel.transform(code, { presets: ['es2015'] });
console.log(result.code); // ES5 output
// </script>