{"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,"search_vec":"'2':30 '2018':26 '3':74 '3.0.1':24 '4':31 'activ':67 'approach':90 'babel':43,60 'babel-plugin-istanbul':59 'code':17 'compar':87 'coverag':18,39,95 'design':27 'file':10 'flexibl':86 'function':71 'instrument':3,8,15 'integr':44 'istanbul':2,13,40,62,94 'istanbul-instrumenter-load':1 'istanbul-lib-instru':12 'javascript':9,91 'karma':35,38 'karma-coverage-istanbul-report':37 'latest':20 'lib':14 'limit':85 'loader':4,6,52,54,93 'longer':66 'maintain':68 'march':25 'must':46 'newer':89 'option':78 'plugin':61 'post':51 'post-load':50 'primarili':32 'project':75 'report':19,41 'run':47 'schema':81 'schema-util':80 'stabl':21 'still':70 'supersed':57 'support':42 'use':33 'util':82 'valid':77 'version':22 'via':79 'webpack':5,29,73,92","created_at":"2026-04-25T11:21:34.444266+00:00","updated_at":"2026-04-25T11:21:34.444266+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/webpack-contrib/istanbul-instrumenter-loader","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/istanbul-instrumenter-loader","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-24","install_tag":null}}