esbuild-plugin-babel-flow

raw JSON →
0.0.5 verified Fri May 01 auth: no javascript

An esbuild plugin for stripping Flow type annotations from JavaScript files using Babel under the hood. Current version is 0.0.5, released as an early-stage package. It integrates into the esbuild plugin system via the 'onLoad' event, transforming code with Babel's transform API to remove Flow types for safe execution. Key differentiators: it bridges esbuild's lack of native Flow support by leveraging Babel's flow-strip-types preset. Alternative plugins exist (e.g., esbuild-plugin-flow), but this one explicitly uses Babel for compatibility. Note that peer dependency esbuild ^0.14.23 is required.

error Error: Cannot find module 'esbuild-plugin-babel-flow'
cause Package not installed or not in node_modules.
fix
Run npm install esbuild-plugin-babel-flow --save-dev
error TypeError: esbuild.build is not a function
cause Incorrect esbuild import; common mistake importing default from esbuild.
fix
Use import { build } from 'esbuild'
error ReferenceError: require is not defined in ES module scope
cause Using CommonJS require in an ES module package.json with "type": "module".
fix
Use import { babelFlowPlugin } from 'esbuild-plugin-babel-flow'
gotcha Plugin does not perform type checking; it only strips types. Use Flow separately for type validation.
fix Run flow check before or after bundling.
gotcha esbuild peer dependency must be ^0.14.23. Using other versions may cause incompatibility.
fix Ensure esbuild version meets requirement.
gotcha The plugin applies Babel transformation to all loaded JS files, which may slow down builds for large codebases.
fix Use esbuild's filter option to only apply plugin to files containing Flow annotations.
breaking No breaking changes documented as package is very early (v0.0.5). API subject to change.
fix Pin version and monitor releases.
npm install esbuild-plugin-babel-flow
yarn add esbuild-plugin-babel-flow
pnpm add esbuild-plugin-babel-flow

Demonstrates setting up esbuild with the Flow-stripping plugin, bundling a file with Flow type annotations.

import { build } from 'esbuild';
import { babelFlowPlugin } from 'esbuild-plugin-babel-flow';

build({
  entryPoints: ['example.flow.js'],
  bundle: true,
  outdir: 'dist',
  plugins: [babelFlowPlugin()],
}).catch(() => process.exit(1));
// Ensure package.json has "type": "module" or use .mjs extension