vite-plugin-toml
raw JSON → 0.8.7 verified Mon Apr 27 auth: no javascript
A Vite and Rollup plugin for importing TOML files. Current stable version is 0.8.7, with updates aligned to Vite's release cadence. Uses toml-eslint-parser for TOML 1.0.0 support. Supports both Vite and Rollup despite the name. Key differentiator: integrates directly as a Vite/Rollup plugin with options for named exports and big integers, unlike alternatives that require separate TOML parsing libraries.
Common errors
error ViteToml is not defined ↓
cause Incorrect import style (default import instead of named import).
fix
Change to import { ViteToml } from 'vite-plugin-toml'
error Unrecognized TOML syntax: <line> ↓
cause TOML file contains TOML 0.5.0 syntax not supported in TOML 1.0.0.
fix
Update TOML file to comply with TOML 1.0.0 spec.
error TypeScript cannot find module './file.toml' ↓
cause Missing type declaration for .toml files.
fix
Add declare module '*.toml' { const value: unknown; export default value; } to a .d.ts file.
Warnings
breaking v0.3.0 dropped support for TOML 0.5.0 and only supports TOML 1.0.0. ↓
fix Ensure your TOML files conform to TOML 1.0.0 spec.
deprecated The package name 'vite-plugin-toml' is historical; the plugin also works with Rollup but the name may mislead. ↓
fix No change needed; just note it works with Rollup too.
gotcha Default import returns the parsed object; named imports (like import { key } from './file.toml') only work when namedExports option is true. ↓
fix Enable namedExports option or use default import.
gotcha Using require() syntax (CommonJS) may not work in Vite/ESM environments; prefer ESM imports. ↓
fix Use import statements instead of require().
Install
npm install vite-plugin-toml yarn add vite-plugin-toml pnpm add vite-plugin-toml Imports
- ViteToml wrong
import ViteToml from 'vite-plugin-toml'correctimport { ViteToml } from 'vite-plugin-toml' - default import for .toml files wrong
import { data } from './config.toml'correctimport data from './config.toml' - TypeScript module declaration wrong
declare module '*.toml' { const value: Record<string, unknown>; export default value; }correctdeclare module '*.toml' { const value: unknown; export default value; }
Quickstart
// vite.config.ts
import { ViteToml } from 'vite-plugin-toml'
// basic usage
export default {
plugins: [ViteToml()]
}
// with named exports
export default {
plugins: [ViteToml({ namedExports: true })]
}
// Rollup usage (rollup.config.js)
import { ViteToml } from 'vite-plugin-toml'
export default {
plugins: [ViteToml()]
}