vite-plugin-http2-proxy
raw JSON → 0.5.1 verified Mon Apr 27 auth: no javascript
A Vite plugin that enables HTTP/2 proxy support for development servers. Current stable version v0.5.1 supports Vite 2 through 7 with TypeScript types. It wraps the underlying http-proxy and provides HTTP/2 connectivity, which is not natively supported by Vite's built-in proxy. Unlike Vite's default http-proxy configuration, this plugin handles the `http2` session negotiation transparently. Released occasionally with focus on compatibility across major Vite versions.
Common errors
error Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'vite-plugin-http2-proxy' ↓
cause Missing package installation or wrong import path.
fix
Run
npm install vite-plugin-http2-proxy --save-dev and ensure import path is correct. error ERR_REQUIRE_ESM: require() of ES Module not supported ↓
cause Using CommonJS `require()` with ESM-only package version.
fix
Use
import or switch to dynamic import: const plugin = await import('vite-plugin-http2-proxy'). error TypeError: Cannot read properties of undefined (reading 'proxy') ↓
cause Plugin called without configuration object.
fix
Pass a configuration object to the plugin function, e.g.,
vitePluginHttp2Proxy({ '/api': { target: '...' } }). error Error: connect ECONNREFUSED ↓
cause Backend server is not running or rejecting connections.
fix
Ensure your target server is up and accepting connections on the specified port.
Warnings
breaking ESM-only since v0.5.0; CommonJS `require()` will throw. ↓
fix Use dynamic import or switch project to ESM.
gotcha Proxy options are merged with Vite's own proxy configuration; naming conflicts may cause silent failures. ↓
fix Avoid reusing the same path key in both Vite's `server.proxy` and this plugin.
gotcha HTTP/2 support requires Node.js >=10.0.0 and a target that actually supports HTTP/2. ↓
fix Verify your backend server is configured for HTTP/2 (e.g., h2 or h2c).
deprecated The `session` option was deprecated in v0.4.0 in favor of automatic session management. ↓
fix Remove `session` from proxy configuration; it is now handled internally.
Install
npm install vite-plugin-http2-proxy yarn add vite-plugin-http2-proxy pnpm add vite-plugin-http2-proxy Imports
- default wrong
const vitePluginHttp2Proxy = require('vite-plugin-http2-proxy')correctimport vitePluginHttp2Proxy from 'vite-plugin-http2-proxy' - vitePluginHttp2Proxy wrong
import { vitePluginHttp2Proxy } from 'vite-plugin-http2-proxy'correctimport vitePluginHttp2Proxy from 'vite-plugin-http2-proxy' - type ProxyOptions wrong
import { ProxyOptions } from 'vite-plugin-http2-proxy'correctimport type { ProxyOptions } from 'vite-plugin-http2-proxy'
Quickstart
import { defineConfig } from 'vite';
import vitePluginHttp2Proxy from 'vite-plugin-http2-proxy';
export default defineConfig({
plugins: [
vitePluginHttp2Proxy({
'/api': {
target: 'https://http2.example.com',
changeOrigin: true,
},
}),
],
});