rollup-plugin-es3

raw JSON →
1.1.0 verified Mon Apr 27 auth: no javascript

Rollup plugin that removes ES3-incompatible constructs (Object.defineProperty and Object.freeze) from the bundled output. Version 1.1.0 is the latest stable release. It is a lightweight, focused alternative to large transpilers, specifically addressing rollup's __esModule marker and frozen objects for legacy environments.

error Error: "Object.defineProperty is not defined"
cause Plugin not applied or configured incorrectly.
fix
Ensure plugin is installed and added to rollup plugins array: plugins: [es3()]
error TypeError: es3 is not a function
cause Default import used with require instead of import.
fix
Use import es3 from 'rollup-plugin-es3' or const es3 = require('rollup-plugin-es3').default
gotcha Plugin only removes Object.defineProperty and Object.freeze; it does not handle other ES3 incompatibilities like reserved words or trailing commas.
fix Use additional plugins (e.g., rollup-plugin-es5) for broader ES3 compatibility.
breaking v1.0.2 removed support for Object.freeze removal by default (breaking change if relied on).
fix Update to v1.0.2+; pass { remove: ['freeze'] } to re-enable.
deprecated Object.freeze removal is disabled by default since v1.0.2 and may be removed entirely.
fix Use explicit option { remove: ['freeze'] } if needed.
npm install rollup-plugin-es3
yarn add rollup-plugin-es3
pnpm add rollup-plugin-es3

Shows basic usage of the plugin: install, import, and add to rollup plugins array.

import { rollup } from 'rollup';
import es3 from 'rollup-plugin-es3';

const bundle = await rollup({
  input: 'src/index.js',
  plugins: [es3()],
});
await bundle.write({ file: 'dist/bundle.js', format: 'iife' });