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.
Common errors
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
Warnings
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.
Install
npm install rollup-plugin-es3 yarn add rollup-plugin-es3 pnpm add rollup-plugin-es3 Imports
- default
import es3 from 'rollup-plugin-es3' - named wrong
const { rollupPluginES3 } = require('rollup-plugin-es3')correctimport { rollupPluginES3 } from 'rollup-plugin-es3' - type
import type { RollupPluginES3Options } from 'rollup-plugin-es3'
Quickstart
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' });