gulp-babel-external-helpers
raw JSON → 2.2.2 verified Sat Apr 25 auth: no javascript maintenance
A gulp plugin that replaces gulp-babel by transpiling files with Babel while automatically collecting external helpers into a separate module. Version 2.2.2 is the latest stable release, with sporadic updates. It avoids polluting the global scope with babel helpers by generating a shared helpers file and injecting require statements into each transpiled file. Unlike gulp-babel or manual babel setup, it automates external helper management without global pollution.
Common errors
error Error: Cannot find module 'gulp-babel-helpers' ↓
cause Package not installed or missing in node_modules
fix
Run 'npm install gulp-babel-helpers --save-dev'
error TypeError: babelHelpers is not a function ↓
cause Incorrect import style (e.g., using destructured named import)
fix
Use 'import babelHelpers from ...' or 'const babelHelpers = require(...).default'
error Error: Babel config must specify 'externalHelpers' option ↓
cause Missing externalHelpers configuration in babel options
fix
Add 'externalHelpers: true' to your babel config object
error Error: ENOENT: no such file or directory, open '.../helpers.js' ↓
cause Imaginary location path does not match the generated file stream
fix
Ensure the second argument to babelHelpers matches the filename that will be created in the dest
Warnings
gotcha The 'imaginaryLocationInSrc' parameter must be a relative path as if it existed in the source directory. Using an absolute path or incorrect relative path will cause broken require statements in the output. ↓
fix Ensure the second argument is a relative path from the source root, e.g., './helpers.js' for a file at src/helpers.js.
gotcha If the babel config does not include 'externalHelpers: true' or the necessary plugins, helpers may not be extracted correctly. ↓
fix Set '@babel/plugin-external-helpers' or 'externalHelpers: true' in your babel config.
deprecated Package is no longer actively maintained; consider using '@babel/preset-env' with 'useBuiltIns' or 'babel-plugin-external-helpers' directly with gulp-babel. ↓
fix Switch to gulp-babel + babel-plugin-external-helpers or a more modern setup.
Install
npm install gulp-babel-helpers yarn add gulp-babel-helpers pnpm add gulp-babel-helpers Imports
- babelHelpers wrong
const babelHelpers = require('gulp-babel-helpers')correctimport babelHelpers from 'gulp-babel-helpers' - babelHelpers (as transform) wrong
const { babelHelpers } = require('gulp-babel-helpers')correctimport babelHelpers from 'gulp-babel-helpers'; const transform = babelHelpers; - Require in CommonJS wrong
const babelHelpers = require('gulp-babel-helpers')correctconst babelHelpers = require('gulp-babel-helpers').default || require('gulp-babel-helpers')
Quickstart
import gulp from 'gulp';
import babelHelpers from 'gulp-babel-helpers';
gulp.task('scripts', () => {
return gulp.src('./src/**/*.js')
.pipe(babelHelpers(
{
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-runtime']
},
'./helpers.js'
))
.pipe(gulp.dest('./dist'));
});