{"record":{"id":"9346f202169fd064","repo":"facebook/flow","slug":"flow-option-must-be-all-or-detect","errorCode":null,"errorMessage":"flow option must be \"all\" or \"detect\"","messagePattern":"flow option must be \"all\" or \"detect\"","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/flow-parser/oxidized-src/index.js","lineNumber":41,"sourceCode":"import * as StripFlowTypesForBabel from './estree/StripFlowTypesForBabel';\nimport * as TransformESTreeToBabel from './babel/TransformESTreeToBabel';\nimport * as StripFlowTypes from './estree/StripFlowTypes';\n\nconst DEFAULTS: {flow: 'detect'} = {\n  flow: 'detect',\n};\n\nfunction getOptions(opts?: ParserOptions): ParserOptions {\n  // Always build a fresh object so we never mutate the caller's input.\n  // Repeated calls with the same `opts` reference must produce identical\n  // results — earlier versions wrote normalized fields back onto `opts`,\n  // poisoning subsequent calls.\n  const options: ParserOptions = {...DEFAULTS, ...(opts ?? {})};\n\n  // Default to detecting whether to parse Flow syntax by the presence\n  // of an @flow pragma.\n  if (options.flow !== 'all' && options.flow !== 'detect') {\n    throw new Error('flow option must be \"all\" or \"detect\"');\n  }\n\n  if (options.sourceType === 'unambiguous') {\n    // Clear source type so that it will be detected from the contents of the file\n    delete options.sourceType;\n  } else if (\n    options.sourceType != null &&\n    options.sourceType !== 'script' &&\n    options.sourceType !== 'module'\n  ) {\n    throw new Error(\n      'sourceType option must be \"script\", \"module\", or \"unambiguous\" if set',\n    );\n  }\n\n  if (options.enableExperimentalComponentSyntax == null) {\n    options.enableExperimentalComponentSyntax = true; // Enable by default\n  }","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/facebook/flow/blob/d1341dac899a79c027762f6b423d896045287620/packages/flow-parser/oxidized-src/index.js#L23-L59","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Use `flow: 'all'` if every input is Flow, or `flow: 'detect'` / omit it (the default) to require an @flow pragma","Search your codebase for `flow:` in parser option objects and fix each invalid value","If you meant plain-JS parsing, use 'detect' and don't add a pragma"],"exampleFix":"// before\nparse(source, { flow: true });\n\n// after\nparse(source, { flow: 'all' });","handlingStrategy":"validation","validationCode":"const FLOW_VALUES = new Set(['all', 'detect']);\n\nfunction validParserOptions(opts: {flow?: unknown}): boolean {\n  return opts?.flow == null || FLOW_VALUES.has(opts.flow as string);\n}\n\n// parse(source, opts) only after validParserOptions(opts) passes","typeGuard":"function isFlowOption(\n  v: unknown,\n): v is 'all' | 'detect' | undefined {\n  return v == null || v === 'all' || v === 'detect';\n}","tryCatchPattern":"try {\n  parse(source, opts);\n} catch (err) {\n  if (err.message === 'flow option must be \"all\" or \"detect\"') {\n    opts = {...opts, flow: undefined}; // fall back to the default\n    parse(source, opts);\n  } else throw err;\n}","preventionTips":["Type the options object in TypeScript so invalid values fail at compile time","Do not port boolean flags from babel/hermes options verbatim","Omit the option to get the safe 'detect' default"],"tags":["flow-parser","options","validation"],"backgroundTag":"invalid-option-value","analyzedSha":"d1341dac899a79c027762f6b423d896045287620","analyzedAt":"2026-08-17T00:07:02.212Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}