facebook/flow · error · Error

flow option must be "all" or "detect"

Error message

flow option must be "all" or "detect"

What it means

The Flow parser package (wasm build) validates its options object: options.flow must be 'all' (parse everything as Flow) or 'detect' (parse as Flow only with an @flow pragma). Any other value — including booleans — throws immediately.

Source

Thrown at packages/flow-parser/oxidized-src/index.js:41

import * as StripFlowTypesForBabel from './estree/StripFlowTypesForBabel';
import * as TransformESTreeToBabel from './babel/TransformESTreeToBabel';
import * as StripFlowTypes from './estree/StripFlowTypes';

const DEFAULTS: {flow: 'detect'} = {
  flow: 'detect',
};

function getOptions(opts?: ParserOptions): ParserOptions {
  // Always build a fresh object so we never mutate the caller's input.
  // Repeated calls with the same `opts` reference must produce identical
  // results — earlier versions wrote normalized fields back onto `opts`,
  // poisoning subsequent calls.
  const options: ParserOptions = {...DEFAULTS, ...(opts ?? {})};

  // Default to detecting whether to parse Flow syntax by the presence
  // of an @flow pragma.
  if (options.flow !== 'all' && options.flow !== 'detect') {
    throw new Error('flow option must be "all" or "detect"');
  }

  if (options.sourceType === 'unambiguous') {
    // Clear source type so that it will be detected from the contents of the file
    delete options.sourceType;
  } else if (
    options.sourceType != null &&
    options.sourceType !== 'script' &&
    options.sourceType !== 'module'
  ) {
    throw new Error(
      'sourceType option must be "script", "module", or "unambiguous" if set',
    );
  }

  if (options.enableExperimentalComponentSyntax == null) {
    options.enableExperimentalComponentSyntax = true; // Enable by default
  }

View on GitHub (pinned to d1341dac89)

Solutions

  1. Use `flow: 'all'` if every input is Flow, or `flow: 'detect'` / omit it (the default) to require an @flow pragma
  2. Search your codebase for `flow:` in parser option objects and fix each invalid value
  3. If you meant plain-JS parsing, use 'detect' and don't add a pragma

Example fix

// before
parse(source, { flow: true });

// after
parse(source, { flow: 'all' });
Defensive patterns

Strategy: validation

Validate before calling

const FLOW_VALUES = new Set(['all', 'detect']);

function validParserOptions(opts: {flow?: unknown}): boolean {
  return opts?.flow == null || FLOW_VALUES.has(opts.flow as string);
}

// parse(source, opts) only after validParserOptions(opts) passes

Type guard

function isFlowOption(
  v: unknown,
): v is 'all' | 'detect' | undefined {
  return v == null || v === 'all' || v === 'detect';
}

Try / catch

try {
  parse(source, opts);
} catch (err) {
  if (err.message === 'flow option must be "all" or "detect"') {
    opts = {...opts, flow: undefined}; // fall back to the default
    parse(source, opts);
  } else throw err;
}

Prevention

When it happens

Trigger: Calling parse(code, {flow: ...}) with an invalid value such as `flow: true`, 'auto', 'yes', or 'none'; passing an options object built for a different parser that used boolean flags.

Common situations: Migrating configs from babel-style plugins or older hermes-parser options that used booleans; copy-pasted snippets; intending 'no flow syntax' and spelling it wrong (the correct form is 'detect' with no pragma in the file).

Related errors


AI-assisted analysis of facebook/flow@d1341dac89 (2026-08-17). Data as JSON: /api/errors/9346f202169fd064. Report an issue: GitHub.