rollup-plugin-istanbul
raw JSON → 5.0.0 verified Mon Apr 27 auth: no javascript
A Rollup plugin that provides seamless integration with Istanbul for code coverage. Version 5.0.0 supports Rollup v4 and uses istanbul-lib-instrument v6.0.1. Dropped Node.js 14 support in v5.0.0. Key differentiator: instruments source files before bundling to avoid instrumenting test code, with source map support. Released occasionally, maintained actively.
Common errors
error Error: Cannot find module 'rollup-plugin-istanbul' ↓
cause Package not installed or missing from dependencies.
fix
Run npm install --save-dev rollup-plugin-istanbul
error TypeError: istanbul is not a function ↓
cause Using named import instead of default import.
fix
Use import istanbul from 'rollup-plugin-istanbul' (default import).
error Error: [plugin:istanbul] This plugin only works with Rollup >=1.20.0 ↓
cause Using an older version of Rollup.
fix
Upgrade Rollup to ^1.20.0||^2.0.0||^3.0.0||^4.0.0.
error Error: Could not resolve source map from instrumented file ↓
cause produceSourceMap is false or Rollup output sourcemap is disabled.
fix
Set instrumenterConfig.produceSourceMap: true and output.sourcemap: 'inline' or true.
Warnings
breaking Node.js 14 dropped in v5.0.0; requires Node.js 16+. Also istanbul-lib-instrument v6.0.1 may have breaking changes in options. ↓
fix Upgrade Node.js to >=16 and review istanbul-lib-instrument migration.
breaking v4.0.0: Dropped support for Node.js 10 and 12; istanbul-lib-instrument updated to v5.2.1. ↓
fix Use Node.js >=14 or stay on v3.x.
breaking v3.0.0: Defaults for autoWrap, preserveComments, esModules, produceSourceMap changed to true. Rollup minimum version 1.20.0. istanbul-lib-instrument v4.0.3. ↓
fix Explicitly set old defaults if needed; ensure Rollup >=1.20.0.
breaking v2.0.0: Switched from deprecated istanbul to istanbul-lib-instrument. API changed. ↓
fix Update instrumenterConfig options per istanbul-lib-instrument docs.
gotcha The 'include' option defaults to all files if omitted; be sure to use 'exclude' to skip test files. ↓
fix Always set exclude or include patterns to avoid instrumenting tests.
gotcha Source maps must be enabled in both the plugin (produceSourceMap: true) and Rollup output for accurate coverage. ↓
fix Set output.sourcemap: true or 'inline' in Rollup config.
Install
npm install rollup-plugin-istanbul yarn add rollup-plugin-istanbul pnpm add rollup-plugin-istanbul Imports
- default wrong
const istanbul = require('rollup-plugin-istanbul')correctimport istanbul from 'rollup-plugin-istanbul' - IstanbulPluginOptions (TypeScript)
import type { IstanbulPluginOptions } from 'rollup-plugin-istanbul' - require() in CommonJS wrong
const { istanbul } = require('rollup-plugin-istanbul')correctconst istanbul = require('rollup-plugin-istanbul')
Quickstart
import { rollup } from 'rollup';
import istanbul from 'rollup-plugin-istanbul';
const bundle = await rollup({
input: 'src/index.js',
plugins: [
istanbul({
exclude: ['test/**/*.js', 'node_modules/**'],
instrumenterConfig: {
esModules: true,
compact: true,
produceSourceMap: true,
autoWrap: true,
preserveComments: true
}
})
]
});
await bundle.write({
file: 'dist/bundle.js',
format: 'iife'
});