{"id":22789,"library":"vite-plugin-proxy-middleware","title":"vite-plugin-proxy-middleware","description":"A Vite plugin that resolves the conflict between using HTTP/2 (h2) and Vite's built-in proxy. When HTTPS is enabled for HTTP/2, Vite's proxy configuration becomes incompatible. This plugin provides a separate proxy table configuration via a file path or object, enabling both HTTP/2 and proxy to work simultaneously. v1.0.2 is stable. Requires Vite with HTTPS enabled. Alternative to manually working around the conflict.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/williamyorkl/vite-plugin-proxy-middleware","tags":["javascript","typescript"],"install":[{"cmd":"npm install vite-plugin-proxy-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-proxy-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-proxy-middleware","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Vite plugin, requires Vite as peer dependency","package":"vite","optional":false}],"imports":[{"note":"ESM default export. CommonJS require not supported.","wrong":"const VitePluginProxyMiddleware = require('vite-plugin-proxy-middleware')","symbol":"default","correct":"import VitePluginProxyMiddleware from 'vite-plugin-proxy-middleware'"},{"note":"Not a named export; use default import.","wrong":"import { VitePluginProxyMiddleware } from 'vite-plugin-proxy-middleware'","symbol":"VitePluginProxyMiddleware","correct":"import VitePluginProxyMiddleware from 'vite-plugin-proxy-middleware'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite'\nimport VitePluginProxyMiddleware from 'vite-plugin-proxy-middleware'\n\nexport default defineConfig({\n  plugins: [\n    VitePluginProxyMiddleware({\n      proxyTable: {\n        '/api': {\n          target: 'https://api.example.com',\n          changeOrigin: true,\n          rewrite: (path) => path.replace(/^\\/api/, '')\n        }\n      },\n      mockPath: '/dev-mock'\n    })\n  ],\n  server: {\n    https: {\n      key: './localhost-key.pem',\n      cert: './localhost.pem'\n    }\n    // Do NOT use Vite's proxy here\n  }\n})","lang":"typescript","description":"Shows basic configuration with proxy table object, HTTPS setup for HTTP/2, and note to avoid Vite's native proxy option."},"warnings":[{"fix":"Remove server.proxy from vite.config; use plugin's proxyTable instead.","message":"Vite's built-in proxy must be disabled (do not set server.proxy) when using this plugin.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Generate SSL certificates and set server.https in vite.config.","message":"HTTPS must be enabled for HTTP/2 to work; plugin requires server.https configuration.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure proxy-table.js/ts exports an object like { dev: { ... }, prod: { ... } }.","message":"proxyTable option can be a path string (e.g., './proxy-table') but the file must export an object with environment keys (dev, test, gray, prod).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Include rewrite in proxy rule: { target: '...', rewrite: (path) => path.replace(/^\\/api/, '') }","message":"The plugin uses http-proxy-middleware internally, but with a slightly different API; rewrite function must be defined on each rule.","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":"Add proxyTable: { ... } or proxyTable: './path/to/proxy-table' to VitePluginProxyMiddleware options.","cause":"Missing proxyTable option in plugin configuration.","error":"Error: The 'proxyTable' option is required."},{"fix":"Ensure the proxy table file exists at the specified path and exports an object.","cause":"When proxyTable is a file path, the file does not exist or is not accessible.","error":"Error: Cannot find module './proxy-table'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}