Registry / testing / vite-log-capture

vite-log-capture

JSON →
library0.1.4jsnpmunverified

Vite plugin that captures console logs and HMR errors during development, allowing inspection and assertion of log output. Current stable version is 0.1.4 (released July 2024). Active development. Differentiators: integrates directly with Vite's HMR pipeline, captures both standard console logs and HMR-specific errors, and provides a simple API to retrieve captured logs for testing or debugging. Unlike generic log interceptors, it works seamlessly with Vite's dev server.

npm install vite-log-capture
INSTALL
IMPORT
SIG · VITE-LOG-CAPTURE
V
vite-log-capture
testingjavascriptv0.1.4
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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

captureLogs
import { captureLogs } from 'vite-log-capture'
const captureLogs = require('vite-log-capture')
ESM-only module. CommonJS require() will error.
getCapturedLogs
import { getCapturedLogs } from 'vite-log-capture'
import { captureLogs, getCapturedLogs } from 'vite-log-capture/cjs'
No subpath exports. Import from package root only.
ViteLogCapture
import { ViteLogCapture } from 'vite-log-capture'
import ViteLogCapture from 'vite-log-capture'
Named export, not default.

Shows basic plugin setup in vite.config.ts, capturing console logs in application code, and retrieving captured logs.

// vite.config.ts import { defineConfig } from 'vite'; import { captureLogs, ViteLogCapture } from 'vite-log-capture'; export default defineConfig({ plugins: [ViteLogCapture()], }); // In your application code captureLogs(); console.log('test log'); console.error('test error'); const logs = getCapturedLogs(); console.log(logs); // [{ level: 'log', message: 'test log' }, { level: 'error', message: 'test error' }]
Debug
Known issues
breakingPlugin only works with Vite 7.0.0 or above.
fix
Upgrade Vite to version 7.0.0 or later.
affects: >=0.1.0
gotchacaptureLogs() must be called before any console logs you want to capture. Logs before the call are not captured.
fix
Call captureLogs() at the earliest point in your application, typically before any imports or module evaluation.
affects: >=0.1.0
gotchagetCapturedLogs() returns a new array each time; it does not clear the internal buffer. To clear logs, use clearCapturedLogs().
fix
After retrieving logs, call clearCapturedLogs() to avoid accumulating duplicate entries.
affects: >=0.1.0
Errors
Common errors & fixes
Error: [vite-log-capture] Vite version must be ^7.0.0
Currently using Vite version below 7.0.0.
fix
Run 'npm install vite@latest' to upgrade to Vite 7.0.0+.
TypeError: require() of ES Module not supported
Trying to use require() to import the module instead of import.
fix
Use import statement instead: 'import { captureLogs } from "vite-log-capture"'
Uncaught ReferenceError: captureLogs is not defined
captureLogs() was called before the import was evaluated (e.g., in a module where import order matters).
fix
Ensure import { captureLogs } from 'vite-log-capture' is at the top of the file and that the plugin is applied before using captureLogs.
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies
viterequiredpeer dependency required at version ^7.0.0
Agent activity
39 hits · last 30 days
node
33
Amazon
1
OpenAI (training)
1
Resources