vite-yaml-plugin

raw JSON →
2.0.4 verified Mon Apr 27 auth: no javascript

Vite plugin to import YAML files (.yaml/.yml) as JavaScript modules, using js-yaml internally. Version 2.0.4, actively maintained, minimal dependencies (only js-yaml as a dependency, vite as peer). Key differentiator: lightweight alternative to vite-plugin-yaml, supports TypeScript declaration augmentation, configurable file matching and yaml options. Suitable for Vite projects needing YAML data imports with zero configuration overhead.

error Cannot find module 'vite-yaml-plugin' or its corresponding type declarations.
cause Missing TypeScript types setup.
fix
Add 'vite-yaml-plugin/types' to compilerOptions.types in tsconfig.json, or provide a custom declaration file.
error The requested module 'vite-yaml-plugin' does not provide an export named 'default'
cause Using default import instead of named import.
fix
Change import statement to: import { yamlPlugin } from 'vite-yaml-plugin'
error TypeError: yamlPlugin is not a function
cause Passing the function reference instead of calling it in the plugins array.
fix
Use yamlPlugin() with parentheses in the plugins array.
gotcha Plugin must be called as a function, not passed directly as object.
fix Use `yamlPlugin()` instead of `yamlPlugin` in the plugins array.
gotcha TypeScript ambient types require adding 'vite-yaml-plugin/types' to compilerOptions.types, not just importing.
fix Add 'vite-yaml-plugin/types' to the 'types' array in tsconfig.json.
deprecated Older versions (1.x) may have used a different import path or default export.
fix Update to v2 and use named import { yamlPlugin } from 'vite-yaml-plugin'.
npm install vite-yaml-plugin
yarn add vite-yaml-plugin
pnpm add vite-yaml-plugin

Shows basic setup of the plugin in vite.config.js and usage in a module, plus TypeScript type augmentation.

// vite.config.js
import { defineConfig } from 'vite';
import { yamlPlugin } from 'vite-yaml-plugin';

export default defineConfig({
  plugins: [
    yamlPlugin(),
  ],
});

// Then in any module:
import foo from './foo.yaml';
console.log(foo);

// For TypeScript, add to tsconfig.json:
// {
//   "compilerOptions": {
//     "types": ["vite-yaml-plugin/types"]
//   }
// }