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.

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
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.
npm install coverage-istanbul-loader
yarn add coverage-istanbul-loader
pnpm add coverage-istanbul-loader

Configures Webpack to instrument JavaScript files for code coverage using Istanbul, with modern options.

// 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.