vite-plugin-csv

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

A Vite plugin that enables importing CSV files directly into JavaScript/TypeScript code, returning parsed JSON arrays. Version 1.0.0 stable. It works with Vite 2.x and above, supports any framework (React, Vue, Svelte, etc.), and ships TypeScript declarations. Unlike manual CSV parsing, it integrates seamlessly with Vite's import system and hot module replacement.

error Cannot find module './data.csv' or its corresponding type declarations.
cause TypeScript cannot resolve .csv imports without a module declaration.
fix
Create a .d.ts file with declare module '*.csv' { const data: any; export default data; }
error Uncaught TypeError: CSV is not a function
cause Plugin was imported using named import instead of default import.
fix
Use import CSV from 'vite-plugin-csv' instead of import { CSV } from 'vite-plugin-csv'.
gotcha Without a TypeScript shim, importing a .csv file in a .ts file will cause a type error.
fix Add a declaration file with `declare module '*.csv' {}` to your project.
gotcha Plugin only works with Vite v2 and above. Older versions not supported.
fix Upgrade Vite to ^2.0.0 or later.
gotcha The CSV is parsed synchronously at build time. Large CSV files may impact build performance.
fix Consider splitting large CSVs or using a runtime parser for dynamic data.
gotcha Imported CSV data is bundled into the output, so sensitive information may be exposed.
fix Do not import CSV files with sensitive data; load them via fetch at runtime instead.
npm install vite-plugin-csv
yarn add vite-plugin-csv
pnpm add vite-plugin-csv

Shows how to install, configure the plugin in vite.config.js, and import a CSV file.

// vite.config.js
import { defineConfig } from 'vite';
import CSV from 'vite-plugin-csv';

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

// any .js/.ts file
import data from './data.csv';
console.log(data); // [{"col1": "val1"}, ...]