ember-cli-babel-plugin-helpers

raw JSON →
1.1.1 verified Sat Apr 25 auth: no javascript

Utilities for managing Babel plugins in Ember CLI apps and addons. Provides functions to check, find, and add plugins (hasPlugin, findPlugin, addPlugin) while preventing duplicate registrations. Targets can be EmberApp, Addon instances, or arrays. Handles Babel's plugin name normalization, including scoped packages and Windows path fixes. Current stable version 1.1.1, ships TypeScript types. Minimal dependencies; primarily for addon authors who need to ensure specific Babel plugins are present in a parent project without collisions.

error TypeError: (0 , _emberCliBabelPluginHelpers.hasPlugin) is not a function
cause Using ES module import syntax (import { hasPlugin } from '...') on a CommonJS-only package.
fix
Replace with const { hasPlugin } = require('ember-cli-babel-plugin-helpers') in your code.
error Cannot find module 'ember-cli-babel-plugin-helpers'
cause The package is not installed or is missing from node_modules.
fix
Run npm install ember-cli-babel-plugin-helpers --save-dev (or yarn add --dev) in your Ember addon project.
error addPlugin expects pluginConfig to be a string or an array of up to 3 elements
cause Passing an invalid structure (e.g., an object with name property) as pluginConfig.
fix
Pass a string (plugin name) or an array [name, options?, identifier?] as the second argument.
error Assertion Failed: You cannot call ember-cli-babel-plugin-helpers functions on a target that is not an EmberApp, addon, or array
cause Passing a bare object or other type as the target argument.
fix
Use the parent from the addon's included hook, or pass an explicit array of plugin configurations.
gotcha Package uses CommonJS (require) only; ESM import will throw a runtime error. Do not use import statements.
fix Replace import { hasPlugin } from 'ember-cli-babel-plugin-helpers' with const { hasPlugin } = require('ember-cli-babel-plugin-helpers')
gotcha On Windows, scoped package names (like @babel/plugin-x) were not correctly normalized before v1.0.2, causing hasPlugin to fail matching.
fix Upgrade to >=1.0.2 or normalize manually using the package's internal normalization (not exposed).
gotcha Passing a target that is not an EmberApp, Addon, or array leads to unexpected behavior or errors (e.g., using a plain object without babel property).
fix Ensure target is either the parent from included(), an array of plugins, or has a babel property with plugins array.
breaking Rename from ember-cli-babel-plugin-helpers? Not applicable, but note that v1.0.0 introduced TypeScript types; no breaking API changes known.
fix N/A (no real breaking change documented)
gotcha addPlugin with before/after constraints that conflict with each other or with existing plugin ordering will cause a runtime error (conflict detection is not graceful).
fix Review existing plugin order; call addPlugin only if constraints can be satisfied, or catch errors.
npm install ember-cli-babel-plugin-helpers
yarn add ember-cli-babel-plugin-helpers
pnpm add ember-cli-babel-plugin-helpers

Shows how an Ember addon uses hasPlugin and addPlugin to conditionally add a Babel plugin if not already present.

const { hasPlugin, addPlugin } = require('ember-cli-babel-plugin-helpers');

// Inside an Ember addon's included hook
module.exports = {
  name: require('./package').name,

  included(parent) {
    this._super.included.apply(this, arguments);

    if (!hasPlugin(parent, '@babel/plugin-proposal-class-properties')) {
      addPlugin(parent, require.resolve('@babel/plugin-proposal-class-properties'));
    }
  }
};