Registry /
testing / istanbul-instrumenter-loader
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Use in webpack config
✓ // webpack.config.js
{
test: /\.js$/,
use: { loader: 'istanbul-instrumenter-loader', options: { esModules: true } },
enforce: 'post',
exclude: /node_modules|\.spec\.js$/
}
✗ // Using require() in webpack config as a plugin
const IstanbulLoader = require('istanbul-instrumenter-loader');
This loader is used declaratively in webpack config (module.rules), not imported directly.
options
✓ // valid options object
{
esModules: true,
compact: true,
produceSourceMap: false
}
✗ // omitting required fields or using invalid options
{
esModules: 'yes',
compact: 1,
coverageVariable: undefined
}
Options are validated by schema-utils; invalid types will throw errors.
test
✓ // pattern for test index file
const tests = require.context('./src/components/', true, /\.js$/);
tests.keys().forEach(tests);
const components = require.context('../src/components/', true, /\.js$/);
components.keys().forEach(components);
✗ // using wildcard require without context
require('../src/**/*.js')
Karma webpack setup requires require.context for dynamic loading; wildcard require is not supported by webpack.
Sets up Karma with webpack preprocessor, instruments source files with Istanbul, and collects coverage reports.
// Install
npm install --save-dev istanbul-instrumenter-loader
// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['mocha', 'chai'],
files: ['test/index.js'],
preprocessors: { 'test/index.js': ['webpack'] },
webpack: {
module: {
rules: [{
test: /\.js$/,
use: { loader: 'istanbul-instrumenter-loader', options: { esModules: true } },
enforce: 'post',
exclude: /node_modules|\.spec\.js$/
}]
}
},
reporters: ['progress', 'coverage-istanbul'],
coverageIstanbulReporter: {
reports: ['text-summary'],
fixWebpackSourcePaths: true
},
browsers: ['ChromeHeadless']
});
};
// test/index.js
const tests = require.context('./src/components/', true, /\.spec\.js$/);
tests.keys().forEach(tests);
const components = require.context('../src/', true, /\.js$/);
components.keys().forEach(components);
Errors
Common errors & fixes
Error: istanbul-instrumenter-loader requires webpack >= 2.0.0
Using webpack 1.x with loader (v3+) that requires webpack 2+
fixUpgrade webpack to v2.0.0 or higher, or use the older version 2.0.0 of this loader.
Module build failed: TypeError: Cannot read property 'instrument' of undefined
Missing or incorrect istanbul-lib-instrument dependency; this loader depends on it internally.
fixRun npm install istanbul-lib-instrument --save-dev or ensure it is installed as a peer dep.
Invalid options object. Istanbul Instrumenter Loader has been initialized using an options object that does not match the API schema.
Options validation fails due to unsupported property or wrong type
fixCheck loaded docs for valid options (esModules, compact, etc.) and ensure types (Boolean, String, Function) are correct.
Audit
Dependencies
webpackrequiredThis is a webpack loader and requires webpack at runtime
schema-utilsoptionalUsed for options validation (since v3.0.0)