babel-plugin-es6-promise

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

Babel plugin that rewrites Promise references to the es6-promise polyfill only when necessary (i.e., when the native Promise is not available). Version 1.1.1 is the latest stable release. Key differentiator: it conditionally loads the polyfill based on environment, reducing bundle size for modern platforms. Requires es6-promise as a separate dependency (peer dependency). Tested with Node 0.10+, but primarily useful for legacy browser support and older Node versions.

error Module not found: Can't resolve 'es6-promise'
cause Missing es6-promise peer dependency.
fix
Run npm install --save es6-promise.
error Cannot find module 'babel-plugin-es6-promise'
cause Plugin not installed or incorrectly named in Babel config.
fix
Ensure plugin is installed: npm install --save-dev babel-plugin-es6-promise. Use short name 'es6-promise' in config, not the full 'babel-plugin-es6-promise'.
error ReferenceError: Promise is not defined
cause Plugin transformation not applied; likely because file does not reference Promise or Babel is not configured.
fix
Check Babel config includes "plugins": ["es6-promise"] and run Babel on files that use Promise.
breaking Requires es6-promise as a separate installation; not bundled.
fix Run `npm install --save es6-promise` in addition to the plugin.
gotcha Uses CommonJS require() not ES imports; may conflict with other import/export transforms.
fix Avoid combining with other Babel plugins that rely on ES module syntax transformations.
gotcha Variable name '_Promise' is generated by Babel and may conflict with user code if using a similar pattern.
fix Use unique variable names in your code; the plugin renames all Promise references globally.
deprecated Package is in maintenance mode; no updates since 2016, lacks support for modern JavaScript features like async/await.
fix Consider modern alternatives like @babel/plugin-transform-runtime with core-js or polyfill-service.
npm install babel-plugin-es6-promise
yarn add babel-plugin-es6-promise
pnpm add babel-plugin-es6-promise

Setup and usage of babel-plugin-es6-promise: install, configure Babel, and see the transformation with conditional polyfill loading.

// Install dependencies
npm install --save-dev babel-plugin-es6-promise es6-promise

// .babelrc
{
  "plugins": ["es6-promise"]
}

// Input file (main.js)
const promise = new Promise((resolve) => resolve('hello'));
promise.then(console.log);

// Run babel
npx babel main.js

// Output (example):
var _Promise = typeof Promise === 'undefined'
  ? require('es6-promise').Promise
  : Promise;

var promise = new _Promise(function (resolve) {
  resolve('hello');
});
promise.then(console.log);