Registry / testing / istanbul-instrumenter-loader

istanbul-instrumenter-loader

JSON →
library3.0.1jsnpmunverified

Webpack loader that instruments JavaScript files with istanbul-lib-instrument for code coverage reporting. Latest stable version is 3.0.1 (March 2018). Designed for webpack 2–4, primarily used with Karma and karma-coverage-istanbul-reporter. Supports Babel integration but must run as a post-loader. The loader has been superseded by babel-plugin-istanbul and is no longer actively maintained, but still functional for webpack 3 projects. It validates options via schema-utils but has limited flexibility compared to newer approaches.

npm install istanbul-instrumenter-loader
INSTALL
IMPORT
SIG · ISTANBUL-INSTRUMEN
I
istanbul-instrumenter-loader
testingjavascriptv3.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 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);
Debug
Known issues
deprecatedThis loader is no longer actively maintained. Use babel-plugin-istanbul or c8 for new projects.
fix
Switch to babel-plugin-istanbul with @babel/preset-env and @babel/preset-react for Babel projects, or use c8 for native ESM support.
affects: >=0.0.0
breakingv3.0.0 drops Node.js < 4.3 and < 5.10 support. Engines field now enforces >= 4.3 < 5.0.0 || >= 5.10.
fix
Upgrade Node.js to v6+ (LTS) or use v2.0.0 if stuck on older Node.
affects: >=3.0.0
breakingv3.0.0 introduces schema validation via schema-utils. Invalid options now throw an error instead of being silently ignored.
fix
Ensure options object matches the schema. Check istanbul-lib-instrument API docs for valid option types.
affects: >=3.0.0
gotchaMust set enforce: 'post' when using with Babel to avoid double instrumentation.
fix
Add enforce: 'post' to the rule and exclude node_modules and test files.
affects: >=0.0.0
gotchaSourcemaps may break if not configured correctly. Use fixWebpackSourcePaths: true in karma-coverage-istanbul-reporter.
fix
Set coverageIstanbulReporter.fixWebpackSourcePaths to true in karma.conf.js
affects: >=0.0.0
Errors
Common errors & fixes
Error: istanbul-instrumenter-loader requires webpack >= 2.0.0
Using webpack 1.x with loader (v3+) that requires webpack 2+
fix
Upgrade 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.
fix
Run 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
fix
Check loaded docs for valid options (esModules, compact, etc.) and ensure types (Boolean, String, Function) are correct.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
webpackrequiredThis is a webpack loader and requires webpack at runtime
schema-utilsoptionalUsed for options validation (since v3.0.0)
Agent activity
4 hits · last 30 days
node
4
Resources
istanbul-instrumenter-loader — npm install istanbul-instrumenter-loader · libregistry