Vite Plugin Auto Origin
raw JSON → 2.0.2 verified Mon Apr 27 auth: no javascript
A Vite plugin that automatically configures server.origin to the external URL of the Vite dev server, essential for backend integration scenarios where assets (images, fonts) must be loaded from the dev server URL rather than the backend. Version 2.0.2 supports Vite 5+, ships TypeScript types, and is ESM-only since v2. Active maintenance with frequent updates aligned with Vite major releases. Differentiator: handles proxy chains automatically without manual configuration.
Common errors
error require() of ES Module /node_modules/vite-plugin-auto-origin/dist/index.js from /project/vite.config.js not supported. ↓
cause Using CommonJS require() on an ESM-only package (v2+).
fix
Change to import statement or downgrade to v1.x.
error TypeError: autoOrigin is not a function ↓
cause Calling autoOrigin as a value without parentheses, or importing incorrectly.
fix
Use autoOrigin() (call the factory function) in the plugins array.
error Error: The plugin 'vite-plugin-auto-origin' requires Vite >=5.0.0 ↓
cause Installing v2.x with an older Vite version.
fix
Upgrade Vite to ^5.0 || ^6.0 || ^7.0 || ^8.0 or install v1.x (npm install vite-plugin-auto-origin@1).
Warnings
breaking Version 2.0.0 drops CommonJS support. The package is ESM-only. ↓
fix Use import/ESM syntax. If CJS is required, stick to v1.x.
deprecated Vite 5 is the minimum supported version in v2.x. Older Vite versions are not supported. ↓
fix Upgrade Vite to ^5.0 || ^6.0 || ^7.0 || ^8.0
gotcha The plugin does not work with Vite 4 or earlier. Ensure Vite version is compatible. ↓
fix Use vite-plugin-auto-origin@1.x for Vite 4, or upgrade Vite to 5+.
gotcha In some proxy configurations, the plugin may detect the internal proxy URL instead of the external URL. Manual override via options may be needed. ↓
fix Pass options to autoOrigin({ origin: 'https://your-external-url' }) to force the origin.
Install
npm install vite-plugin-auto-origin yarn add vite-plugin-auto-origin pnpm add vite-plugin-auto-origin Imports
- autoOrigin wrong
const autoOrigin = require('vite-plugin-auto-origin')correctimport autoOrigin from 'vite-plugin-auto-origin' - AutoOriginOptions
import type { AutoOriginOptions } from 'vite-plugin-auto-origin' - Plugin wrong
const plugin = autoOrigin; (missing function call)correctimport type { Plugin } from 'vite'; import autoOrigin from 'vite-plugin-auto-origin'; const plugin: Plugin = autoOrigin()
Quickstart
import { defineConfig } from 'vite';
import autoOrigin from 'vite-plugin-auto-origin';
export default defineConfig({
plugins: [autoOrigin()],
// server.origin will be set automatically
});