rollup-plugin-istanbul
raw JSON → 2.0.2 verified Mon Apr 27 auth: no javascript
Rollup plugin for seamless integration with Istanbul code coverage instrumentation. Current stable version is 5.0.0, released with support for Rollup v4 and Node.js 16+. It instruments source files before bundling, ensuring test code is not covered. Key differentiators: works as a Rollup plugin, supports source maps, configurable instrumenter options, and minimal setup. Published under MIT license, maintained by artberri. Released at a moderate cadence with 5 major versions.
Common errors
error Error: 'default' is not exported by rollup-plugin-istanbul ↓
cause Using named import { istanbul } instead of default import in ESM.
fix
Use: import istanbul from 'rollup-plugin-istanbul';
error TypeError: istanbul is not a function ↓
cause In CommonJS, require returns an object with .default property.
fix
Use: const istanbul = require('rollup-plugin-istanbul').default;
error Error: Cannot find module 'istanbul-lib-instrument' ↓
cause Missing dependency for istanbul-lib-instrument.
fix
Run: npm install --save-dev istanbul-lib-instrument
Warnings
breaking v2.0.0: Switch from istanbul to istanbul-lib-instrument; older istanbul options no longer work. ↓
fix Update to >=2.0.0 and use istanbul-lib-instrument compatible options (see instrumenterConfig).
breaking v3.0.0: Defaults for autoWrap, preserveComments, esModules, produceSourceMap changed to true. Minimum Node.js 10 required. ↓
fix If you relied on old defaults, explicitly set these options to false in instrumenterConfig.
breaking v4.0.0: Dropped Node 10 and 12, istanbul-lib-instrument version ^5.2.1; coverage location fix may change output. ↓
fix Upgrade Node to >=14 and test coverage output for changes.
breaking v5.0.0: Dropped Node 14, Rollup v4 required, istanbul-lib-instrument ^6.0.1. ↓
fix Upgrade Node to >=16, Rollup to >=4, and update instrumenterConfig if needed.
gotcha Plugin applies to all files in include glob by default; test files must be excluded to avoid instrumenting test code. ↓
fix Always set 'exclude' option (e.g., exclude: ['test/**/*.js']) to prevent instrumenting test files.
deprecated The 'compact' option in plugin options is deprecated; use instrumenterConfig.compact instead. ↓
fix Pass compact via instrumenterConfig: { compact: true }.
Install
npm install rollup-plugin-istanbul2 yarn add rollup-plugin-istanbul2 pnpm add rollup-plugin-istanbul2 Imports
- default (istanbul) wrong
import { istanbul } from 'rollup-plugin-istanbul'correctimport istanbul from 'rollup-plugin-istanbul' - require (CJS) wrong
const istanbul = require('rollup-plugin-istanbul');correctconst istanbul = require('rollup-plugin-istanbul').default; - TypeScript usage
import istanbul from 'rollup-plugin-istanbul';
Quickstart
// Install: npm install --save-dev rollup rollup-plugin-istanbul
// rollup.config.js
import istanbul from 'rollup-plugin-istanbul';
export default {
input: 'src/index.js',
output: { file: 'dist/bundle.js', format: 'iife' },
plugins: [
istanbul({
exclude: ['test/**/*.js']
})
]
};