Flow-bin: Flow Type Checker Binary Wrapper
Flow-bin is a wrapper package that provides the Flow static type checker binary for JavaScript projects. Developed primarily by Facebook/Meta, Flow offers static analysis capabilities similar to TypeScript, inferring types and catching errors before runtime. The package, currently at version `0.310.0`, bundles the corresponding Flow `0.310.0` binary, making it accessible via `npm` or `yarn` scripts and programmatically through Node.js's `child_process` module. While Flow itself is still actively developed and utilized internally at Meta, its public GitHub repository has been archived, meaning external contributions are no longer accepted, and community support is more limited. This positions `flow-bin` primarily as a maintenance package for delivering Meta's internal Flow updates to the public, rather than an actively evolving open-source project. Its release cadence is tied directly to Flow's internal release schedule. It serves as an alternative to TypeScript for adding static typing to JavaScript projects.
Common errors
-
Error: Command failed: /path/to/node_modules/flow-bin/flow check /bin/sh: /path/to/node_modules/flow-bin/flow: No such file or directory
cause The Flow binary was not found at the expected path, often due to an incomplete `flow-bin` installation or a corrupted package.fixTry running `npm rebuild flow-bin` or `npm install --force` to ensure the package and its binaries are correctly installed. Verify the version you are using is not `0.105.0`. -
Error: Linter: Failed to load Flow config at path. Please make sure that a .flowconfig file is present in your project root or specified using --flowconfig.
cause Flow requires a `.flowconfig` file in the project root to operate. This error indicates it's missing or inaccessible.fixCreate a `.flowconfig` file in your project's root directory. A minimal `.flowconfig` can be empty or include `[options]` and `[ignore]` sections. Refer to Flow documentation for configuration details. -
SyntaxError: Cannot use import statement outside a module
cause Attempting to use ESM `import flowPath from 'flow-bin'` in a Node.js environment configured for CommonJS, or without proper transpilation.fixFor CommonJS environments, use `const flowPath = require('flow-bin');`. If you intend to use ESM, ensure your `package.json` contains `"type": "module"` and your Node.js version supports ESM, or use a bundler like Webpack or Rollup configured for ESM.
Warnings
- breaking The Flow type checker project, which `flow-bin` wraps, has archived its public GitHub repository and no longer accepts external contributions. While still developed internally by Meta, this significantly limits community-driven feature development and direct public bug reporting for the upstream tool.
- gotcha The `flow-bin` package version is directly coupled to the Flow type checker version it bundles. Breaking changes or new features in Flow itself will directly impact users of `flow-bin`, even if `flow-bin`'s wrapper logic hasn't changed.
- gotcha The `flow-bin@v0.105.0` npm release was published without the actual Flow binaries, leading to 'command not found' errors. This required a patch release `v0.105.1`.
Install
-
npm install flow-bin -
yarn add flow-bin -
pnpm add flow-bin
Imports
- flowBinaryPath
import { flowBinaryPath } from 'flow-bin'; // Not a named export. import flowBinaryPath from 'flow-bin'; // May fail in CJS projects without configuration.const flowBinaryPath = require('flow-bin');
Quickstart
const execFile = require('child_process').execFile;
const flow = require('flow-bin');
console.log(`Running Flow from: ${flow}`);
execFile(flow, ['check', '--json'], (err, stdout, stderr) => {
if (err) {
console.error('Flow check failed:', err.message);
if (stderr) console.error('Stderr:', stderr);
try {
const errorOutput = JSON.parse(stdout);
console.error('Flow errors:', JSON.stringify(errorOutput, null, 2));
} catch (parseErr) {
console.error('Stdout (non-JSON on error):', stdout);
}
process.exit(1);
} else {
console.log('Flow check successful.');
try {
const result = JSON.parse(stdout);
if (result.errors && result.errors.length > 0) {
console.warn('Flow reported warnings/errors:', JSON.stringify(result.errors, null, 2));
} else {
console.log('No Flow issues found.');
}
} catch (parseErr) {
console.warn('Could not parse Flow output as JSON:', stdout);
}
}
});