Registry / testing / vite-plugin-istanbul

vite-plugin-istanbul

JSON →
library8.0.0jsnpmunverified

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.

npm install vite-plugin-istanbul
INSTALL
IMPORT
SIG · VITE-PLUGIN-ISTANB
V
vite-plugin-istanbul
testingjavascriptv8.0.0
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.

IstanbulPlugin
import IstanbulPlugin from 'vite-plugin-istanbul'
import { IstanbulPlugin } from 'vite-plugin-istanbul'
Default export only. Named import will resolve to undefined.
type IstanbulPluginOptions
import type { IstanbulPluginOptions } from 'vite-plugin-istanbul'
Type is exported as a named type. Use 'import type' for tree-shaking.
default export usage with require
const IstanbulPlugin = require('vite-plugin-istanbul').default
const IstanbulPlugin = require('vite-plugin-istanbul')
CommonJS users must use '.default' because the module uses ESM default export.

Basic setup: enable Istanbul instrumentation only when VITE_COVERAGE environment variable is set to true, targeting .ts/.vue files in src.

// vite.config.ts import IstanbulPlugin from 'vite-plugin-istanbul'; export default defineConfig({ plugins: [ IstanbulPlugin({ include: 'src/**', exclude: ['node_modules', 'tests/**'], extension: ['.js', '.ts', '.tsx', '.vue'], requireEnv: true // only instruments when VITE_COVERAGE=true }) ] }); // Run: VITE_COVERAGE=true npx vite build
Debug
Known issues
breakingRemoved upper range constraint on Vite peer dependency; may cause conflicts with older Vite versions during install.
fix
Ensure your Vite version is compatible (>=4). If using Vite 5/6, test instrumentation after upgrade.
affects: >=8.0.0
deprecatedrequireEnv option default behavior changed; previously not requiring env by default, now requires explicit 'true'.
fix
Set requireEnv: true explicitly if you want env-gated instrumentation, or set it to false to always instrument.
affects: >=7.0.0
gotchaThe plugin is intended for development/testing only; using it in production may slow down builds and include coverage code in bundles.
fix
Use requireEnv: true and set VITE_COVERAGE=false or unset in production CI.
affects: >=6.0.0
breakingDefault export usage changed; may break projects using CommonJS require without .default property.
fix
Use `const IstanbulPlugin = require('vite-plugin-istanbul').default` for CJS.
affects: >=6.0.0
gotchaInstrumentation may not work with Vite's SSR mode or library mode; only tested with build/serve for client-side code.
fix
If using SSR, consider alternative coverage approaches or test with a separate config.
affects: *
Errors
Common errors & fixes
Cannot find module '@babel/generator'
Missing dependency 'babel__generator' or its types.
fix
Run npm install -D @types/babel__generator (or upgrade to v7.2.1+ where it's included).
TypeError: IstanbulPlugin is not a function
Using named import instead of default import.
fix
Use `import IstanbulPlugin from 'vite-plugin-istanbul'` (no curly braces).
Plugin loaded but no coverage data generated
Environment variable VITE_COVERAGE is not set to 'true' when requireEnv is not explicitly set, or extensions not included.
fix
Set VITE_COVERAGE=true, or set requireEnv: false, and ensure your file extensions match the extension option.
Error: require() of ES Module not supported
Using CommonJS require() on the ESM package.
fix
Use dynamic import: `const IstanbulPlugin = (await import('vite-plugin-istanbul')).default` or configure your project for ESM.
Upgrade
Version history
8.0.0latest on npm
Audit
Dependencies
viterequiredPeer dependency — must be installed in project; version >=4 required.
@types/babel__generatorrequiredRuntime dependency for Babel type generation (added in v7.2.1).
Agent activity
13 hits · last 30 days
node
10
Resources
vite-plugin-istanbul — npm install vite-plugin-istanbul · libregistry