{"id":20672,"library":"vite-plugin-istanbul","title":"vite-plugin-istanbul","description":"Vite plugin that instruments source code with Istanbul/NYC for code coverage, similar to Webpack's istanbul-instrumenter-loader. Current stable version 8.0.0 (released March 2026) supports Vite >=4. Maintained by community with regular releases. Key differentiator: seamless integration with Vite's build pipeline, automatic TypeScript/JSX/Vue support, and optional environment variable gating to avoid instrumenting production builds. Designed for development/test coverage only.","status":"active","version":"8.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/iFaxity/vite-plugin-istanbul","tags":["javascript","vite","babel","plugin","istanbul","nyc","typescript"],"install":[{"cmd":"npm install vite-plugin-istanbul","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-istanbul","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-istanbul","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency — must be installed in project; version >=4 required.","package":"vite","optional":false},{"reason":"Runtime dependency for Babel type generation (added in v7.2.1).","package":"@types/babel__generator","optional":false}],"imports":[{"note":"Default export only. Named import will resolve to undefined.","wrong":"import { IstanbulPlugin } from 'vite-plugin-istanbul'","symbol":"IstanbulPlugin","correct":"import IstanbulPlugin from 'vite-plugin-istanbul'"},{"note":"Type is exported as a named type. Use 'import type' for tree-shaking.","wrong":"","symbol":"type IstanbulPluginOptions","correct":"import type { IstanbulPluginOptions } from 'vite-plugin-istanbul'"},{"note":"CommonJS users must use '.default' because the module uses ESM default export.","wrong":"const IstanbulPlugin = require('vite-plugin-istanbul')","symbol":"default export usage with require","correct":"const IstanbulPlugin = require('vite-plugin-istanbul').default"}],"quickstart":{"code":"// vite.config.ts\nimport IstanbulPlugin from 'vite-plugin-istanbul';\n\nexport default defineConfig({\n  plugins: [\n    IstanbulPlugin({\n      include: 'src/**',\n      exclude: ['node_modules', 'tests/**'],\n      extension: ['.js', '.ts', '.tsx', '.vue'],\n      requireEnv: true // only instruments when VITE_COVERAGE=true\n    })\n  ]\n});\n\n// Run: VITE_COVERAGE=true npx vite build","lang":"typescript","description":"Basic setup: enable Istanbul instrumentation only when VITE_COVERAGE environment variable is set to true, targeting .ts/.vue files in src."},"warnings":[{"fix":"Ensure your Vite version is compatible (>=4). If using Vite 5/6, test instrumentation after upgrade.","message":"Removed upper range constraint on Vite peer dependency; may cause conflicts with older Vite versions during install.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Set requireEnv: true explicitly if you want env-gated instrumentation, or set it to false to always instrument.","message":"requireEnv option default behavior changed; previously not requiring env by default, now requires explicit 'true'.","severity":"deprecated","affected_versions":">=7.0.0"},{"fix":"Use requireEnv: true and set VITE_COVERAGE=false or unset in production CI.","message":"The plugin is intended for development/testing only; using it in production may slow down builds and include coverage code in bundles.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Use `const IstanbulPlugin = require('vite-plugin-istanbul').default` for CJS.","message":"Default export usage changed; may break projects using CommonJS require without .default property.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"If using SSR, consider alternative coverage approaches or test with a separate config.","message":"Instrumentation may not work with Vite's SSR mode or library mode; only tested with build/serve for client-side code.","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":"Run npm install -D @types/babel__generator (or upgrade to v7.2.1+ where it's included).","cause":"Missing dependency 'babel__generator' or its types.","error":"Cannot find module '@babel/generator'"},{"fix":"Use `import IstanbulPlugin from 'vite-plugin-istanbul'` (no curly braces).","cause":"Using named import instead of default import.","error":"TypeError: IstanbulPlugin is not a function"},{"fix":"Set VITE_COVERAGE=true, or set requireEnv: false, and ensure your file extensions match the extension option.","cause":"Environment variable VITE_COVERAGE is not set to 'true' when requireEnv is not explicitly set, or extensions not included.","error":"Plugin loaded but no coverage data generated"},{"fix":"Use dynamic import: `const IstanbulPlugin = (await import('vite-plugin-istanbul')).default` or configure your project for ESM.","cause":"Using CommonJS require() on the ESM package.","error":"Error: require() of ES Module not supported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}