rollup-plugin-corejs

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

A Rollup plugin that injects core-js polyfills based on browserslist configuration. Current stable version is 1.0.2, supporting Rollup 3 and 4. It acts as a wrapper around core-js-builder, enabling polyfill injection without Babel. Key differentiator: similar to Babel's useBuiltIns: 'usage' option, it can detect which APIs are used in your code and include only those polyfills, reducing bundle size. Enforces Node >=20. ESM-only module, ships TypeScript types. Release cadence is low, with occasional dependency updates.

error ERR_REQUIRE_ESM: require() of ES Module from rollup-plugin-corejs not supported.
cause The package is ESM-only but imported using require() in a CommonJS context.
fix
Use import { corejsPlugin } from 'rollup-plugin-corejs' in your Rollup config, or rename the file to .mjs.
error TypeError: corejsPlugin is not a function
cause Improper import or destructuring, e.g., const corejsPlugin = require('rollup-plugin-corejs') returns the module object, not the function directly.
fix
Use destructuring: const { corejsPlugin } = await import('rollup-plugin-corejs') or ESM import.
error Error: Cannot find module 'core-js-builder'
cause core-js-builder is a dependency of the plugin, but it may fail to resolve in some environments.
fix
Ensure core-js is installed as a dev dependency: npm install -D core-js
gotcha Usage-based polyfill detection only analyzes your own code, not third-party dependencies.
fix If third-party polyfills are needed, consider adding them separately or using a different strategy.
breaking v1.0.0 removed the 'summary' option. Using it will throw an error.
fix Remove the summary option from plugin configuration.
deprecated Rollup 3 support is deprecated; future versions may only support Rollup 4.
fix Upgrade to Rollup 4 as soon as possible.
gotcha Node.js version must be >=20.0.0. Older versions will fail to load the plugin.
fix Upgrade Node.js to version 20 or later.
gotcha The package is ESM-only. If your Rollup config uses CommonJS, you must migrate to ESM or use dynamic import.
fix Rename rollup.config.js to rollup.config.mjs or use top-level await with dynamic import.
npm install rollup-plugin-corejs
yarn add rollup-plugin-corejs
pnpm add rollup-plugin-corejs

Shows basic Rollup configuration using the plugin with core-js/es modules and usage-based polyfill detection.

import { corejsPlugin } from 'rollup-plugin-corejs';
import { defineConfig } from 'rollup';

export default defineConfig({
  input: 'src/index.js',
  plugins: [
    corejsPlugin({
      // Use polyfills for ES features only
      modules: 'core-js/es',
      // Only include polyfills for APIs used in your code
      usage: true,
      // Optionally specify targets (defaults to browserslist)
      targets: '> 0.5%, not dead'
    })
  ],
  output: {
    file: 'dist/bundle.js',
    format: 'es'
  }
});