Litestar Vite
raw JSON → 0.22.1 verified Fri May 01 auth: no python
Vite plugin for Litestar that integrates Vite's frontend build tool with the Litestar ASGI framework. Current version 0.22.1, supports Python >=3.10, and is actively maintained with frequent releases.
pip install litestar-vite Common errors
error ModuleNotFoundError: No module named 'litestar_vite' ↓
cause Package not installed or installed in wrong environment.
fix
Run
pip install litestar-vite in the correct Python environment. error litestar.exceptions.ImproperlyConfiguredException: VitePlugin requires a 'ViteConfig' instance with a valid 'bundle_dir' ↓
cause ViteConfig is missing or bundle_dir does not exist.
fix
Ensure you pass a ViteConfig object with bundle_dir set to an existing directory, e.g.,
ViteConfig(bundle_dir='frontend/dist'). error FileNotFoundError: [Errno 2] No such file or directory: 'frontend/hot' ↓
cause The hot file path does not exist, usually because Vite dev server is not running or the path is wrong.
fix
Start the Vite dev server first, or set
hot_file=None in ViteConfig if not needed. Warnings
breaking Version 0.20.0 dropped support for Vite 5. Vite 6+ (including 7 and 8) is required. ↓
fix Upgrade your frontend project to Vite >=6. See the migration guide.
deprecated The `inertia` feature was removed in v0.19.0. Use the separate `litestar-inertia` package instead. ↓
fix Install `litestar-inertia` and update your imports from `litestar_vite.inertia` to `litestar_inertia`.
gotcha The `hot_file` parameter defaults to 'hot' but must point to a file that exists during development (created by Vite). Missing this file causes startup errors. ↓
fix Ensure your Vite dev server is running before starting Litestar, or set `hot_file=None` to disable in production.
gotcha If you use `--frontend-dir` in CLI commands, ensure it matches the `resource_dir` or `bundle_dir` in config. Mismatches cause file-not-found errors. ↓
fix Align the CLI argument with your ViteConfig settings, e.g., `litestar assets init --frontend-dir frontend`.
Imports
- VitePlugin wrong
from litestar.plugins.vite import VitePlugincorrectfrom litestar_vite import VitePlugin - ViteConfig wrong
from litestar.config import ViteConfigcorrectfrom litestar_vite import ViteConfig
Quickstart
from litestar import Litestar
from litestar_vite import VitePlugin, ViteConfig
config = ViteConfig(
bundle_dir='frontend/dist',
resource_dir='frontend/public',
hot_file='frontend/hot',
)
app = Litestar(plugins=[VitePlugin(config)])
# Run with: litestar run