Vite Console Forward Plugin

raw JSON →
2.0.1 verified Mon Apr 27 auth: no javascript

A Vite plugin that forwards browser console logs (console.log, console.warn, console.error, etc.) to the Vite dev server console. v2.0.1 is the latest stable release, requiring Vite ^6.0.0 || ^7.0.0. Released as a single-file TypeScript plugin under MIT. Differentiates from similar tools by being a minimal, no-dependency Vite plugin with configurable endpoints and log levels, and automatic buffering. Useful for debugging in environments where browser dev tools are inaccessible, such as mobile devices or CI pipelines.

error Error: Cannot find module 'vite-console-forward-plugin'
cause Missing installation; package not in node_modules.
fix
npm install vite-console-forward-plugin --save-dev
error TypeError: (0 , vite_console_forward_plugin.consoleForwardPlugin) is not a function
cause Incorrect import style: using default import instead of named import.
fix
Use import { consoleForwardPlugin } from 'vite-console-forward-plugin'
error Error: Vite plugin 'vite-console-forward-plugin' requires Vite >=6.0.0
cause Using Vite 5 or older with v2+ of the plugin.
fix
Either downgrade plugin to v1.0.0 or upgrade Vite to ^6.0.0 || ^7.0.0
breaking v2.0.0 dropped support for Vite 5. Plugins using Vite 5 must stay on v1.x.
fix Use vite-console-forward-plugin@1.0.0 if using Vite 5.
gotcha The endpoint must not conflict with other routes in your Vite project, as the plugin adds a middleware that intercepts POST requests to that path.
fix Use a unique endpoint path (e.g. '/__console_logs__') to avoid conflicts.
gotcha If the plugin is not enabled, no middleware is registered, but the client-side injection still occurs? Check documentation; injection may still happen even if disabled.
fix Set `enabled: false` and ensure the plugin is conditionally included only in dev config.
npm install vite-console-forward-plugin
yarn add vite-console-forward-plugin
pnpm add vite-console-forward-plugin

Configures the plugin in vite.config.ts with enabled toggle, custom endpoint, and forwarded log levels.

import { defineConfig } from 'vite';
import { consoleForwardPlugin } from 'vite-console-forward-plugin';

export default defineConfig({
  plugins: [
    consoleForwardPlugin({
      enabled: process.env.NODE_ENV === 'development',
      endpoint: '/api/debug/client-logs',
      levels: ['log', 'warn', 'error', 'info', 'debug']
    })
  ],
  server: {
    port: 5173
  }
});