{"id":20147,"library":"istanbul-instrumenter-loader","title":"istanbul-instrumenter-loader","description":"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.","status":"maintenance","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/webpack-contrib/istanbul-instrumenter-loader","tags":["javascript","webpack","loader","istanbul","coverage"],"install":[{"cmd":"npm install istanbul-instrumenter-loader","lang":"bash","label":"npm"},{"cmd":"yarn add istanbul-instrumenter-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add istanbul-instrumenter-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This is a webpack loader and requires webpack at runtime","package":"webpack","optional":false},{"reason":"Used for options validation (since v3.0.0)","package":"schema-utils","optional":true}],"imports":[{"note":"This loader is used declaratively in webpack config (module.rules), not imported directly.","wrong":"// Using require() in webpack config as a plugin\nconst IstanbulLoader = require('istanbul-instrumenter-loader');","symbol":"Use in webpack config","correct":"// webpack.config.js\n{\n  test: /\\.js$/,\n  use: { loader: 'istanbul-instrumenter-loader', options: { esModules: true } },\n  enforce: 'post',\n  exclude: /node_modules|\\.spec\\.js$/\n}"},{"note":"Options are validated by schema-utils; invalid types will throw errors.","wrong":"// omitting required fields or using invalid options\n{\n  esModules: 'yes',\n  compact: 1,\n  coverageVariable: undefined\n}","symbol":"options","correct":"// valid options object\n{\n  esModules: true,\n  compact: true,\n  produceSourceMap: false\n}"},{"note":"Karma webpack setup requires require.context for dynamic loading; wildcard require is not supported by webpack.","wrong":"// using wildcard require without context\nrequire('../src/**/*.js')","symbol":"test","correct":"// pattern for test index file\nconst tests = require.context('./src/components/', true, /\\.js$/);\ntests.keys().forEach(tests);\nconst components = require.context('../src/components/', true, /\\.js$/);\ncomponents.keys().forEach(components);"}],"quickstart":{"code":"// Install\nnpm install --save-dev istanbul-instrumenter-loader\n\n// karma.conf.js\nmodule.exports = function(config) {\n  config.set({\n    frameworks: ['mocha', 'chai'],\n    files: ['test/index.js'],\n    preprocessors: { 'test/index.js': ['webpack'] },\n    webpack: {\n      module: {\n        rules: [{\n          test: /\\.js$/,\n          use: { loader: 'istanbul-instrumenter-loader', options: { esModules: true } },\n          enforce: 'post',\n          exclude: /node_modules|\\.spec\\.js$/\n        }]\n      }\n    },\n    reporters: ['progress', 'coverage-istanbul'],\n    coverageIstanbulReporter: {\n      reports: ['text-summary'],\n      fixWebpackSourcePaths: true\n    },\n    browsers: ['ChromeHeadless']\n  });\n};\n\n// test/index.js\nconst tests = require.context('./src/components/', true, /\\.spec\\.js$/);\ntests.keys().forEach(tests);\nconst components = require.context('../src/', true, /\\.js$/);\ncomponents.keys().forEach(components);","lang":"javascript","description":"Sets up Karma with webpack preprocessor, instruments source files with Istanbul, and collects coverage reports."},"warnings":[{"fix":"Switch to babel-plugin-istanbul with @babel/preset-env and @babel/preset-react for Babel projects, or use c8 for native ESM support.","message":"This loader is no longer actively maintained. Use babel-plugin-istanbul or c8 for new projects.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Upgrade Node.js to v6+ (LTS) or use v2.0.0 if stuck on older Node.","message":"v3.0.0 drops Node.js < 4.3 and < 5.10 support. Engines field now enforces >= 4.3 < 5.0.0 || >= 5.10.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Ensure options object matches the schema. Check istanbul-lib-instrument API docs for valid option types.","message":"v3.0.0 introduces schema validation via schema-utils. Invalid options now throw an error instead of being silently ignored.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Add enforce: 'post' to the rule and exclude node_modules and test files.","message":"Must set enforce: 'post' when using with Babel to avoid double instrumentation.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Set coverageIstanbulReporter.fixWebpackSourcePaths to true in karma.conf.js","message":"Sourcemaps may break if not configured correctly. Use fixWebpackSourcePaths: true in karma-coverage-istanbul-reporter.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Upgrade webpack to v2.0.0 or higher, or use the older version 2.0.0 of this loader.","cause":"Using webpack 1.x with loader (v3+) that requires webpack 2+","error":"Error: istanbul-instrumenter-loader requires webpack >= 2.0.0"},{"fix":"Run npm install istanbul-lib-instrument --save-dev or ensure it is installed as a peer dep.","cause":"Missing or incorrect istanbul-lib-instrument dependency; this loader depends on it internally.","error":"Module build failed: TypeError: Cannot read property 'instrument' of undefined"},{"fix":"Check loaded docs for valid options (esModules, compact, etc.) and ensure types (Boolean, String, Function) are correct.","cause":"Options validation fails due to unsupported property or wrong type","error":"Invalid options object. Istanbul Instrumenter Loader has been initialized using an options object that does not match the API schema."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}