{"id":19087,"library":"babel-plugin-istanbul","title":"babel-plugin-istanbul","description":"Babel plugin that instruments JavaScript code with Istanbul coverage. Version 8.0.0 (stable) requires Node >=18 and Babel 7/8. It automatically detects test files via nyc's exclude/include patterns and respects inline source maps. Unlike manual instrumentation, this plugin integrates seamlessly with existing Babel pipelines and tools like karma-coverage and nyc. Released as part of the istanbuljs project with regular updates and LTS support. Key differentiator: zero-config setup with nyc and Karma, and no need for separate coverage preprocessor.","status":"active","version":"8.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/istanbuljs/babel-plugin-istanbul","tags":["javascript","istanbul","babel","plugin","instrumentation"],"install":[{"cmd":"npm install babel-plugin-istanbul","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-istanbul","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-istanbul","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used to exclude files from instrumentation based on exclude/include patterns (breaking change in v8.0.0 updated to latest version)","package":"test-exclude","optional":false}],"imports":[{"note":"Default import works in ESM environments. For older Node versions, use require but ensure Babel is configured to handle it.","wrong":"const babelPluginIstanbul = require('babel-plugin-istanbul')","symbol":"default","correct":"import babelPluginIstanbul from 'babel-plugin-istanbul'"},{"note":"CommonJS usage: direct require works; no need to destructure default.","wrong":"const { default: babelPluginIstanbul } = require('babel-plugin-istanbul');","symbol":"babelPluginIstanbul","correct":"const babelPluginIstanbul = require('babel-plugin-istanbul');"},{"note":"In .babelrc or babel.config.js, use the shorthand name 'istanbul' not the full package name.","wrong":"plugins: ['babel-plugin-istanbul']","symbol":"plugin configuration","correct":"plugins: ['istanbul'] or plugins: [['istanbul', { exclude: ['**/*.spec.js'] }]]"}],"quickstart":{"code":"// Install: npm install --save-dev babel-plugin-istanbul\n// In .babelrc:\n{\n  \"env\": {\n    \"test\": {\n      \"plugins\": [\"istanbul\"]\n    }\n  }\n}\n// In package.json, configure nyc to not re-instrument:\n\"nyc\": {\n  \"sourceMap\": false,\n  \"instrument\": false\n}\n// Run tests: npx nyc --reporter=lcov --reporter=text npx mocha test/*.js","lang":"javascript","description":"Shows minimal setup to instrument code with babel-plugin-istanbul: install, configure .babelrc for test env, configure nyc to skip own instrumentation, and run tests with nyc."},"warnings":[{"fix":"Upgrade Node to 12 or later","message":"Node 8 and 10 dropped","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Review exclude/include patterns; test-exclude now uses glob matching based on minimatch","message":"test-exclude update in v8.0.0 may change file exclusion behavior","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Move exclude/include options to Babel plugin array: [\"istanbul\", { exclude: [\"**/*.spec.js\"] }]","message":"Plugin options passed directly to babel-plugin-istanbul are now preferred over package.json 'nyc' config","severity":"deprecated","affected_versions":">=6.0.0"},{"fix":"Set useInlineSourceMaps: false in plugin options if multiple build steps cause memory bloat.","message":"When using with ts-loader or other transpilers, ensure inline source maps are handled correctly. Setting useInlineSourceMaps to false can avoid memory issues.","severity":"gotcha","affected_versions":"*"},{"fix":"Add 'nyc': { 'sourceMap': false, 'instrument': false }","message":"Must set nyc.sourceMap and nyc.instrument to false in package.json to avoid double instrumentation","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Update to babel-plugin-istanbul 7.0.0 or later, or ensure Babel config does not apply block scoping transform before instrumentation.","cause":"Block scoping transform conflicts with instrumentation","error":"Error: container is falsy"},{"fix":"Run: npm install --save-dev babel-plugin-istanbul","cause":"Plugin not installed or not in devDependencies","error":"Error: Cannot find module 'babel-plugin-istanbul'"},{"fix":"Run: npm install --save-dev test-exclude","cause":"Missing dependency when using babel-plugin-istanbul v8 with npm <7 that doesn't auto-install peer dependencies","error":"Error: Cannot find module 'test-exclude'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}