babel-helpers
raw JSON → 6.24.1 verified Sat Apr 25 auth: no javascript
A collection of helper functions used by Babel transforms, such as `typeof`, `extends`, `inherits`, and others. Current stable version is v7.x (e.g., v7.29.2), with v8.0.0-rc.3 as the next major pre-release. The package is part of the Babel monorepo and is released on the same cadence as Babel core (typically monthly or as needed). Key differentiator: it provides the internal helper functions that Babel plugins use to generate runtime code, and it is not intended for direct use by most developers; instead, the helpers are bundled into output via `@babel/plugin-transform-runtime` or `@babel/preset-env`.
Common errors
error Cannot find module 'babel-helpers' ↓
cause Package is not installed or not in node_modules.
fix
Run npm install --save-dev babel-helpers
error TypeError: helpers.get is not a function ↓
cause Importing the default export instead of the named export.
fix
Use import { get } from 'babel-helpers' instead of import helpers from 'babel-helpers'
error Error: Unknown helper: myHelper ↓
cause Requested helper name does not exist.
fix
Use helpers.list() to get all available helper names.
Warnings
breaking babel-helpers v6 and v7 have breaking changes in helper APIs. Direct use of helpers package is discouraged; use @babel/plugin-transform-runtime or @babel/preset-env instead. ↓
fix Update to latest v7.x or v8.x and prefer using plugins that handle helpers automatically.
deprecated Some helpers may be deprecated in future versions. Always check the changelog for deprecations. ↓
fix Stay updated with Babel releases and use the specific plugin that provides the helper.
gotcha Importing from 'babel-helpers' does not work in browser environments without a bundler. The package is designed for Node.js and requires transformation. ↓
fix Use a bundler like webpack or rollup with babel-loader to include helpers.
gotcha The 'get' function expects a string name and returns an AST node. If the name is invalid, it may throw or return undefined. ↓
fix Validate helper names using the 'list' function or refer to the Babel source code.
Install
npm install babel-helpers yarn add babel-helpers pnpm add babel-helpers Imports
- get wrong
import helpers from 'babel-helpers'correctimport { get } from 'babel-helpers' - list wrong
const list = require('babel-helpers').listcorrectimport { list } from 'babel-helpers' - all wrong
const helpers = require('babel-helpers')correctimport * as helpers from 'babel-helpers'
Quickstart
import { get } from 'babel-helpers';
import * as t from 'babel-types';
const typeofHelper = get('typeof');
console.log(t.isExpressionStatement(typeofHelper)); // true