coverage-istanbul-loader
raw JSON → 3.0.5 verified Sat Apr 25 auth: no javascript
A Webpack loader that uses Istanbul to add code coverage instrumentation to JavaScript/TypeScript files. Current stable version is 3.0.5. Release cadence is low; last major update was in 2020. Key differentiators include support for modern Istanbul API (istanbul-lib-instrument) and better source map handling compared to the older istanbul-instrumenter-loader. Ships TypeScript definitions. Requires Node >=10 and Webpack 4+. Works with Karma, TypeScript, and custom options.
Common errors
error Error: Cannot find module '@jsdevtools/coverage-istanbul-loader' ↓
cause Loader not installed or typo in package name.
fix
npm install @jsdevtools/coverage-istanbul-loader --save-dev
error TypeError: loader.run is not a function ↓
cause Using CommonJS require() on ESM-only v3.
fix
Use dynamic import: const loader = (await import('@jsdevtools/coverage-istanbul-loader')).default;
error Module build failed: Error: Cannot find module 'istanbul-lib-instrument' ↓
cause Missing peer dependency.
fix
npm install istanbul-lib-instrument --save-dev
Warnings
breaking Version 3.0 is ESM-only. Using require() will fail with 'require() of ES modules not supported'. ↓
fix Use import or dynamic import(), or downgrade to v2.x.
gotcha Loader must be placed before other loaders (like babel-loader) in webpack config to instrument original source. ↓
fix Ensure this loader is listed last in the 'use' array (i.e., executed first).
deprecated Option 'instrumenter' is deprecated in favor of 'istanbul-lib-instrument' options. ↓
fix Replace 'instrumenter' with 'istanbul-lib-instrument' options (e.g., 'esModules').
gotcha Source maps may not work correctly if options.produceSourceMap is not set to true. ↓
fix Set produceSourceMap: true in loader options.
Install
npm install coverage-istanbul-loader yarn add coverage-istanbul-loader pnpm add coverage-istanbul-loader Imports
- default wrong
const CoverageIstanbulLoader = require('@jsdevtools/coverage-istanbul-loader')correctimport CoverageIstanbulLoader from '@jsdevtools/coverage-istanbul-loader' - loader function wrong
const loader = require('@jsdevtools/coverage-istanbul-loader')correctconst { default: loader } = require('@jsdevtools/coverage-istanbul-loader') - Webpack rule usage wrong
use: 'coverage-istanbul-loader' (without @jsdevtools scope)correctmodule.exports = { module: { rules: [ { test: /\.js$/, use: { loader: '@jsdevtools/coverage-istanbul-loader', options: { esModules: true } } } ] } }
Quickstart
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: '@jsdevtools/coverage-istanbul-loader',
options: {
esModules: true,
produceSourceMap: true
}
}
}
]
}
};
// Run webpack, output bundle will have coverage instrumentation.
// Then run tests with Karma + karma-coverage-istanbul-reporter.