vite-plugin-flow
raw JSON → 0.2.1 verified Mon Apr 27 auth: no javascript
Vite plugin that adds Flow type-stripping support using the Flow parser. Current stable version is 0.2.1, released as a stable build. This plugin integrates with Vite's build pipeline to strip Flow type annotations from .js/.jsx files, allowing Vite to handle Flow-typed code without a separate Babel step. Key differentiators: lightweight (uses the official flow-remove-types package), configurable filtering, optional all-files mode, and pretty-printing. Developed by Eazymov and MIT licensed.
Common errors
error Cannot find module 'vite-plugin-flow' ↓
cause Missing dependency or wrong module resolution due to ESM-only package.
fix
Run 'npm install vite-plugin-flow --save-dev' and ensure project is using ESM (type: module in package.json or .mjs file).
error require() of ES Module ... not supported ↓
cause Using CommonJS require() to import an ES module.
fix
Change to import statement: import vitePluginFlow from 'vite-plugin-flow'
error TypeError: vitePluginFlow is not a function ↓
cause Using named import { vitePluginFlow } instead of default import.
fix
Use import vitePluginFlow from 'vite-plugin-flow' (no braces).
Warnings
gotcha Plugin only works with Vite 2+ (ESM-based). It does not support Vite 1.x. ↓
fix Use Vite 2 or higher.
gotcha File .jsx? filtering by default; if using .mjs or .cjs files, you must provide a custom filter regex. ↓
fix Set filter option like /\.[mc]?jsx?$/ to include .mjs/.cjs.
gotcha The 'all' option bypasses @flow pragma; use with caution as it will attempt to strip types from all JS files regardless of pragma. ↓
fix Only enable 'all' if all your JS files are Flow-typed or you want to be aggressive.
gotcha When using 'pretty: true', the output may change line lengths, which could break source maps if not properly configured. ↓
fix Enable source maps in Vite (build.sourcemap: true) and test thoroughly.
gotcha The 'ignoreUninitializedFields' option is non-standard; it removes uninitialized class fields like 'foo;' or 'foo: string;' which is not spec-compliant. Prefer using 'declare' for type-only fields. ↓
fix Use 'declare foo: string;' instead of 'foo: string;' for type-only fields to avoid needing this option.
Install
npm install vite-plugin-flow yarn add vite-plugin-flow pnpm add vite-plugin-flow Imports
- vitePluginFlow wrong
const vitePluginFlow = require('vite-plugin-flow')correctimport vitePluginFlow from 'vite-plugin-flow' - Options
import type { Options } from 'vite-plugin-flow' - vitePluginFlow (default export) wrong
import { vitePluginFlow } from 'vite-plugin-flow'correctimport vitePluginFlow from 'vite-plugin-flow'
Quickstart
// vite.config.js
import { defineConfig } from 'vite';
import vitePluginFlow from 'vite-plugin-flow';
export default defineConfig({
plugins: [
vitePluginFlow({
all: false,
pretty: false,
ignoreUninitializedFields: false
})
]
});