{"id":21498,"library":"karma-vite","title":"karma-vite","description":"A Karma plugin that uses Vite to transform ES modules for testing. Current stable version is 1.0.5, released December 2023, supporting Vite 2 through 5. It enables using Vite's fast development server and module transformation within Karma test runner. Unlike karma-webpack or karma-rollup, it leverages Vite's on-demand compilation and HMR-like middleware for quicker test re-runs. Requires Karma 6+ and Vite 2-5 as peer dependencies. Ships TypeScript types.","status":"active","version":"1.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/credred/karma-vite","tags":["javascript","karma-plugin","karma-vite","vite","typescript"],"install":[{"cmd":"npm install karma-vite","lang":"bash","label":"npm"},{"cmd":"yarn add karma-vite","lang":"bash","label":"yarn"},{"cmd":"pnpm add karma-vite","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; Karma test runner required to run tests","package":"karma","optional":false},{"reason":"Peer dependency; Vite is used for module transformation and dev server","package":"vite","optional":false}],"imports":[{"note":"The plugin is a Karma framework plugin; it should be registered via 'plugins' array in karma.conf.js, not required directly in test files.","wrong":"const karmaVite = require('karma-vite');","symbol":"karma-vite","correct":"module.exports = (config) => { config.set({ plugins: ['karma-vite'], frameworks: ['vite'] }); };"},{"note":"TypeScript users can import the KarmaViteConfig interface for configuring the vite property in karma.conf.js. CJS require is not supported for types; use import type.","wrong":"const { KarmaViteConfig } = require('karma-vite');","symbol":"KarmaViteConfig","correct":"import type { KarmaViteConfig } from 'karma-vite';"},{"note":"Karma resolves plugin names from npm packages; using require() for the plugin object is unnecessary and can break plugin resolution.","wrong":"plugins: [require('karma-vite')]","symbol":"karma-vite (as a plugin)","correct":"plugins: ['karma-vite']"}],"quickstart":{"code":"// karma.conf.js\nmodule.exports = (config) => {\n  config.set({\n    plugins: ['karma-vite', 'karma-jasmine'],\n    frameworks: ['vite', 'jasmine'],\n    files: [\n      {\n        pattern: 'test/**/*.spec.ts',\n        type: 'module',\n        watched: false,\n        served: false,\n      },\n    ],\n  });\n};","lang":"javascript","description":"Minimal Karma configuration to run Jasmine tests with Vite transformation. Tests are ES modules with .ts extension, and Vite handles TypeScript compilation."},"warnings":[{"fix":"Set type: 'module', watched: false, served: false on all test file entries.","message":"The files pattern must include type: 'module', watched: false, and served: false. Missing these can cause infinite loops or modules not being served.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to 1.0.1 or later. Alternatively, set urlRoot to a non-root path (e.g., '/karma/').","message":"Karma testing never starts if urlRoot is the default value ('/') in Karma config.","severity":"breaking","affected_versions":"1.0.0"},{"fix":"Use Vite 3, 4, or 5 with karma-vite >=1.0.5.","message":"Support for Vite 2 was removed in v1.0.5 (since Vite 2 is no longer maintained).","severity":"deprecated","affected_versions":">=1.0.5"},{"fix":"Upgrade to 1.0.3 or later.","message":"viteClientMiddleware always calls next() even when it should not, causing middleware chaining issues in some Karma setups.","severity":"gotcha","affected_versions":">=1.0.0 <1.0.3"},{"fix":"Upgrade to 1.0.1 or later.","message":"Vite define variables are not applied when using karma-vite v1.0.0.","severity":"gotcha","affected_versions":"1.0.0"},{"fix":"Ensure karma-coverage plugin is installed and add 'coverage' to reporters array in Karma config.","message":"Coverage reports can be generated via vite-plugin-istanbul, but only if 'coverage' reporter is present in Karma config. If coverage reporter is not configured, coverage instrumentation may silently not work.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Set urlRoot to a non-root path (e.g., '/karma/') in karma.conf.js, or upgrade to karma-vite v1.0.1+.","cause":"urlRoot is set to default '/' in Karma config, which conflicts with karma-vite middleware.","error":"Karma never starts. Tests are not executed."},{"fix":"Run 'npm install -D karma-vite'. Ensure 'karma-vite' is listed in the plugins array (not require()'d directly).","cause":"Plugin not installed or not registered correctly in karma config.","error":"Cannot find module 'karma-vite'"},{"fix":"Upgrade to karma-vite v1.0.3 or later.","cause":"viteClientMiddleware receives an undefined response object due to middleware chain issues (affects v1.0.0–1.0.2).","error":"TypeError: Cannot read properties of undefined (reading 'call')"},{"fix":"Upgrade to karma-vite v1.0.1 or later.","cause":"Bug in karma-vite v1.0.0 where Vite's define config is ignored.","error":"Vite config 'define' not working. Environment variables are undefined in tests."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}