Rollup
raw JSON → 2.0.6 verified Fri May 01 auth: no javascript
Rollup is a module bundler for JavaScript that compiles small pieces of code into larger, optimized bundles using ES module format. Current stable version is v4.60.2, with active development and frequent releases. Rollup focuses on ES module tree-shaking and produces smaller, faster bundles compared to other bundlers. It supports plugins, multiple output formats (ESM, CJS, IIFE, UMD, AMD), and has both CLI and JavaScript API. Ships TypeScript types.
Common errors
error Error: Cannot find module 'rollup' ↓
cause Rollup is not installed or used in a non-ESM context.
fix
Run
npm install rollup and ensure your project is configured for ESM (e.g., "type": "module" in package.json or use .mjs file extension). error SyntaxError: Unexpected token 'export' ↓
cause Using ESM syntax in a CommonJS file without proper configuration.
fix
Rename config file to
rollup.config.mjs or add "type": "module" to package.json. error (!) Plugin node-resolve: unable to resolve dependency ... ↓
cause A dependency is missing from node_modules or not resolved by @rollup/plugin-node-resolve.
fix
Install the missing dependency and ensure it is listed in package.json. Also check if the plugin is configured correctly.
error TypeError: Cannot destructure property 'rollup' of ... as it is undefined. ↓
cause Incorrect import pattern when using CommonJS require with ESM-only versions of rollup.
fix
Use
const { rollup } = await import('rollup') or switch to ESM imports. Warnings
breaking Rollup v3 onwards requires Node.js >=14 and uses ESM-only API. ↓
fix Update to Node.js >=14. Use `import` instead of `require()` for rollup API.
breaking Rollup v4 drops support for Node.js 10 and 12. ↓
fix Use Node.js >=14.18.0 (or >=16 for some features).
deprecated Returning import attributes from `load` or `transform` hooks is deprecated in v4.57.0 and will be removed in v5. ↓
fix Use the separate `resolveImportAttributes` hook or attach attributes via module info.
gotcha When using `output.format: 'cjs'`, dynamic imports become `Promise.resolve(require(...))` which is synchronous; use `output.dynamicImportInCjs: false` to keep async behavior. ↓
fix Set `output.dynamicImportInCjs: 'false'` in rollup config.
Install
npm install rollup-esm-206 yarn add rollup-esm-206 pnpm add rollup-esm-206 Imports
- rollup wrong
const rollup = require('rollup')correctimport { rollup } from 'rollup' - RollupOptions wrong
import { RollupOptions } from 'rollup'correctimport type { RollupOptions } from 'rollup' - watch wrong
import watch from 'rollup'correctimport { watch } from 'rollup'
Quickstart
// rollup.config.mjs
export default {
input: 'src/main.js',
output: {
file: 'bundle.js',
format: 'esm'
}
};
// Terminal
// rollup -c rollup.config.mjs