rollup-plugin-flow
raw JSON → 1.1.1 verified Mon Apr 27 auth: no javascript maintenance
A Rollup plugin to strip Flow type annotations from JavaScript/Flow files before bundling, using flow-remove-types under the hood. Current stable version is 1.1.1, with minimal maintenance cadence. It transforms files containing @flow comments by default, with an option to process all files. Provides a 'pretty' mode that removes types without adding whitespace. Differentiators: lightweight and fast compared to full Flow transformation; does not require Flow itself to run; integrates seamlessly with Rollup's build pipeline.
Common errors
error Error: Cannot find module 'flow-remove-types' ↓
cause flow-remove-types is not installed
fix
npm install flow-remove-types --save-dev
error TypeError: flow is not a function ↓
cause Using an older version of the plugin where default export was an object
fix
Update to version 1.1.1 and call
flow() instead of just flow error The plugin does nothing — no types removed ↓
cause Files do not contain @flow comment; `all` option not set
fix
Add
@flow comment to files or set all: true in plugin options error Unexpected token ':' ↓
cause Flow syntax not stripped before bundling; plugin not included or misconfigured
fix
Ensure rollup-plugin-flow is added to plugins array and called correctly
Warnings
gotcha Flow transformation is applied before bundling, so it cannot be combined with other transforms that depend on flow annotations. ↓
fix Ensure this plugin is first in the plugins array if other plugins should see untyped code; else place after Babel if Babel should handle Flow.
gotcha The plugin does not type-check the code; it only removes annotations. For type checking, run Flow separately. ↓
fix Run flow check as a separate step before bundling.
breaking In version 1.1.0, the default export changed from an object to a function. Old usage `plugins: [flow]` will break; must call `flow()` ↓
fix Change `plugins: [flow]` to `plugins: [flow()]` or `plugins: [require('rollup-plugin-flow')()]`
deprecated Rollup changed its plugin API; the plugin expects a `transform` hook that receives `{code, map}`, not `source` ↓
fix Update rollup to a version compatible with the plugin's API (rollup <0.50)
gotcha When using `pretty: true`, source maps are recommended but not generated by default; output may have incorrect line mappings. ↓
fix Set `sourcemap: true` in rollup config and provide input sourcemap if available.
Install
npm install rollup-plugin-flow yarn add rollup-plugin-flow pnpm add rollup-plugin-flow Imports
- default wrong
const flow = require('rollup-plugin-flow');correctimport flow from 'rollup-plugin-flow' - flow function wrong
import { flow } from 'rollup-plugin-flow'correctimport flow from 'rollup-plugin-flow'; plugins: [ flow({ all: true }) ] - usage in rollup config wrong
plugins: [ { transform: ... } ]correctimport flow from 'rollup-plugin-flow'; export default { input: 'src/index.js', plugins: [flow()] }
Quickstart
import flow from 'rollup-plugin-flow';
import { rollup } from 'rollup';
const bundle = await rollup({
input: 'src/index.js',
plugins: [
flow({
all: true,
pretty: false
})
]
});
const { output } = await bundle.generate({ format: 'esm' });
console.log(output[0].code);