flow-webpack-plugin

raw JSON →
1.2.0 verified Sat Apr 25 auth: no javascript

A webpack plugin that invokes the Flow type checker during each webpack compilation. Current version 1.2.0 is stable and actively maintained. It allows Webpack to exit with non-zero return codes if Flow validation fails, supports watch mode, and can reuse a project's existing flow-bin installation without requiring Flow to be on $PATH. Unlike per-file type-checkers, it runs Flow on the entire project.

error TypeError: FlowWebpackPlugin is not a constructor
cause Using ES module import or destructuring require.
fix
Use const FlowWebpackPlugin = require('flow-webpack-plugin'); then new FlowWebpackPlugin(...)
error Error: Cannot find module 'flow-bin'
cause flow-bin not installed and no flowPath option provided.
fix
Install flow-bin: npm install --save-dev flow-bin, or configure flowPath to a Flow binary.
error Flow returned exit code X but webpack continues
cause failOnError or failOnErrorWatch not set to true.
fix
Set failOnError: true (or failOnErrorWatch: true for watch mode) in plugin options.
gotcha flow-webpack-plugin does not provide ES module exports; attempting to import with ESM syntax will fail.
fix Use CommonJS require: const FlowWebpackPlugin = require('flow-webpack-plugin');
gotcha The failOnError option defaults to false; flow errors will not cause webpack to exit with non-zero code unless explicitly set.
fix Set failOnError: true in options to make webpack compilation fail on Flow errors.
gotcha If flow-bin is not installed, the plugin will throw unless flowPath option provides an alternative path.
fix Ensure flow-bin is installed as a devDependency or provide a valid flowPath option.
npm install flow-webpack-plugin
yarn add flow-webpack-plugin
pnpm add flow-webpack-plugin

Example webpack configuration enabling Flow type-checking with error-on-fail settings.

const FlowWebpackPlugin = require('flow-webpack-plugin');

module.exports = {
  plugins: [
    new FlowWebpackPlugin({
      failOnError: true,
      failOnErrorWatch: false,
      reportingSeverity: 'error',
      printFlowOutput: true,
      flowPath: require.main.require('flow-bin'),
      flowArgs: ['--color=always'],
      verbose: false
    }),
  ],
};