Registry / web-framework / babel-plugin-ember-modules-api-polyfill

babel-plugin-ember-modules-api-polyfill

JSON →
library3.5.0jsnpmunverified

babel-plugin-ember-modules-api-polyfill is a Babel plugin designed to facilitate the adoption of the modern JavaScript Modules API (RFC #176) by Ember addon authors. It achieves this by transpiling new module import statements (e.g., `import { inject } from "@ember/service"`) back into their equivalent legacy global object references (e.g., `const inject = Ember.inject.service`) during the build process. This mechanism ensures that addons can leverage contemporary Ember API patterns without sacrificing compatibility with older Ember applications that have not yet fully migrated. Currently at version 3.5.0, the plugin maintains an active release cadence, frequently incorporating bug fixes and enhancements, often driven by updates to the underlying `ember-rfc176-data` package and evolving Ember API requirements. Its primary role is to provide a smooth transition path for Ember applications from a global object dependency model to a more modularized architecture.

npm install babel-plugin-ember-modules-api-polyfill
INSTALL
IMPORT
SIG · BABEL-PLUGIN-EMBER
B
babel-plugin-ember-modules-api-polyfill
web-frameworkjavascriptv3.5.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

babel-plugin-ember-modules-api-polyfill
module.exports = { plugins: ['babel-plugin-ember-modules-api-polyfill'] };
module.exports = { plugins: ['ember-modules-api-polyfill'] };
This plugin is configured by its string name in Babel configurations (e.g., `.babelrc`, `babel.config.js`). Omission of the `babel-plugin-` prefix is a common configuration mistake.
babel-plugin-ember-modules-api-polyfill (with options)
module.exports = { plugins: [['babel-plugin-ember-modules-api-polyfill', { useEmberModule: true }]] };
module.exports = { plugins: ['babel-plugin-ember-modules-api-polyfill', { useEmberModule: true }] };
When passing options to a Babel plugin, the plugin name string and its options object must be nested within an additional array. Failing to do so will result in Babel misinterpreting the configuration.

This quickstart demonstrates how to configure `babel-plugin-ember-modules-api-polyfill` in a `babel.config.js` file and provides an example Ember component utilizing modern module imports that the plugin will transpile to legacy global API access.

// babel.config.js module.exports = { plugins: [ ['babel-plugin-ember-modules-api-polyfill', { // Recommended option for Ember 3.27+ to avoid global window.Ember deprecation useEmberModule: true }] ] }; // src/my-component.js (Example input code) import Component from '@ember/component'; import { inject as service } from '@ember/service'; import { action } from '@ember/object'; import { tracked } from '@glimmer/tracking'; export default class MyComponent extends Component { @service auth; @tracked count = 0; @action increment() { this.count++; console.log(`Current count: ${this.count}`); } constructor() { super(...arguments); console.log('Auth service injected:', this.auth); } } // To apply the transformation with Babel CLI (assuming babel-cli is installed): // npx babel src/my-component.js --out-file dist/my-component.js --config-file babel.config.js // The output in dist/my-component.js would contain code using Ember.Component, Ember.inject.service, etc.
Debug
Known issues
breakingThe plugin's configuration option `blacklist` was renamed to `ignore` in v3.0.0. Using `blacklist` in versions 3.0.0 or newer will cause configuration errors.
fix
Update your Babel configuration to replace `blacklist` with `ignore` for this plugin's options.
affects: >=3.0.0
gotchaFor Ember 3.27+ applications, it is highly recommended to enable the `useEmberModule` option in the plugin's configuration to mitigate `window.Ember` deprecation warnings.
fix
Add `{ useEmberModule: true }` as an option to the plugin configuration in your Babel setup.
affects: >=3.3.0
gotchaThis plugin is designed to operate within the Ember CLI build system via `ember-cli-babel`. Ensure your project's `ember-cli-babel` dependency is version `6.6.0` or higher to guarantee proper integration and expected behavior.
fix
Upgrade `ember-cli-babel` to `^6.6.0` or a newer compatible version in your `package.json`.
affects: N/A (check `ember-cli-babel` version)
Errors
Common errors & fixes
TypeError: Invalid option 'blacklist' passed to 'babel-plugin-ember-modules-api-polyfill'
Using the deprecated `blacklist` configuration option with plugin versions 3.0.0 or later.
fix
Change the `blacklist` option to `ignore` in your `babel-plugin-ember-modules-api-polyfill` configuration.
TypeError: Cannot read properties of undefined (reading 'container')
A bug affecting certain code coverage configurations when using plugin versions prior to 3.2.2.
fix
Upgrade `babel-plugin-ember-modules-api-polyfill` to version `3.2.2` or newer to resolve this bug.
Syntax Error: Decorators must be applied to an identifier, not an alias.
Incorrect transpilation of aliased decorator identifiers within decorated methods in plugin versions prior to 3.2.1.
fix
Upgrade `babel-plugin-ember-modules-api-polyfill` to version `3.2.1` or newer to correctly handle aliased decorators.
Upgrade
Version history
3.5.0latest on npm
Audit
Dependencies
ember-cli-babelrequiredRequired for Ember CLI to detect and apply this plugin in its build pipeline; ensures proper integration and functionality.
Agent activity
14 hits · last 30 days
node
13
OpenAI (training)
1
Resources
babel-plugin-ember-modules-api-polyfill — npm install babel-plugin-ember-modules-api-polyfill · libregistry