{"id":22572,"library":"vite-log-capture","title":"Vite Log Capture","description":"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.","status":"active","version":"0.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/Posterior-AI/vite-log-capture","tags":["javascript","vite","plugin","log","capture","console","hmr","vite-plugin","typescript"],"install":[{"cmd":"npm install vite-log-capture","lang":"bash","label":"npm"},{"cmd":"yarn add vite-log-capture","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-log-capture","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required at version ^7.0.0","package":"vite","optional":false}],"imports":[{"note":"ESM-only module. CommonJS require() will error.","wrong":"const captureLogs = require('vite-log-capture')","symbol":"captureLogs","correct":"import { captureLogs } from 'vite-log-capture'"},{"note":"No subpath exports. Import from package root only.","wrong":"import { captureLogs, getCapturedLogs } from 'vite-log-capture/cjs'","symbol":"getCapturedLogs","correct":"import { getCapturedLogs } from 'vite-log-capture'"},{"note":"Named export, not default.","wrong":"import ViteLogCapture from 'vite-log-capture'","symbol":"ViteLogCapture","correct":"import { ViteLogCapture } from 'vite-log-capture'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport { captureLogs, ViteLogCapture } from 'vite-log-capture';\n\nexport default defineConfig({\n  plugins: [ViteLogCapture()],\n});\n\n// In your application code\ncaptureLogs();\nconsole.log('test log');\nconsole.error('test error');\nconst logs = getCapturedLogs();\nconsole.log(logs); // [{ level: 'log', message: 'test log' }, { level: 'error', message: 'test error' }]","lang":"typescript","description":"Shows basic plugin setup in vite.config.ts, capturing console logs in application code, and retrieving captured logs."},"warnings":[{"fix":"Upgrade Vite to version 7.0.0 or later.","message":"Plugin only works with Vite 7.0.0 or above.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Call captureLogs() at the earliest point in your application, typically before any imports or module evaluation.","message":"captureLogs() must be called before any console logs you want to capture. Logs before the call are not captured.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"After retrieving logs, call clearCapturedLogs() to avoid accumulating duplicate entries.","message":"getCapturedLogs() returns a new array each time; it does not clear the internal buffer. To clear logs, use clearCapturedLogs().","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'npm install vite@latest' to upgrade to Vite 7.0.0+.","cause":"Currently using Vite version below 7.0.0.","error":"Error: [vite-log-capture] Vite version must be ^7.0.0"},{"fix":"Use import statement instead: 'import { captureLogs } from \"vite-log-capture\"'","cause":"Trying to use require() to import the module instead of import.","error":"TypeError: require() of ES Module not supported"},{"fix":"Ensure import { captureLogs } from 'vite-log-capture' is at the top of the file and that the plugin is applied before using captureLogs.","cause":"captureLogs() was called before the import was evaluated (e.g., in a module where import order matters).","error":"Uncaught ReferenceError: captureLogs is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}