{"record":{"id":"d582e00971798fc1","repo":"facebook/flow","slug":"sourcetype-option-must-be-script-module-or","errorCode":null,"errorMessage":"sourceType option must be \"script\", \"module\", or \"unambiguous\" if set","messagePattern":"sourceType option must be \"script\", \"module\", or \"unambiguous\" if set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/flow-parser/oxidized-src/index.js","lineNumber":51,"sourceCode":"  // 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  }\n\n  if (options.enableExperimentalFlowMatchSyntax == null) {\n    options.enableExperimentalFlowMatchSyntax = true; // Enable by default\n  }\n\n  // Record syntax: upstream defaults `enableExperimentalFlowRecordSyntax` to\n  // `true`. The fork's WASM cwrap (FlowParser.js) reads `options.enableRecords`\n  // — a separate, OCaml-aligned key intentionally mirroring\n  // `default_parse_options`. To preserve the upstream-compatible API surface\n  // on the outside while keeping the OCaml-aligned key on the WASM boundary,\n  // bridge: default the upstream key, then mirror it onto the cwrap key. The","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/facebook/flow/blob/5c865861998a8ccb7dbc82b0c1f511e9ef60c3d9/packages/flow-parser/oxidized-src/index.js#L33-L69","documentation":"getOptions in the oxidized flow-parser validates sourceType when set: it must be 'script', 'module', or 'unambiguous' ('unambiguous' is then cleared so detection happens during parsing). Any other string — 'commonjs', 'esm', '' — throws before a parse starts.","triggerScenarios":"parse(code, {sourceType: 'commonjs'}) or other non-enum values, commonly forwarded from user configuration or from tools whose sourceType vocabulary differs (Babel uses 'unambiguous'|'module'|'script', but configs often carry 'commonjs'/'esm' module-system fields that get passed by mistake).","commonSituations":"Config plumbing where package.json \"type\" or bundler settings ('commonjs'/'esm') are mapped directly to parser sourceType; typos; passing undefined-via-empty-string defaults.","solutions":["Map module-system names to parser values: 'esm' -> 'module', 'commonjs' -> 'script', auto -> 'unambiguous'.","Omit sourceType entirely if you want the parser default rather than sending '' or null.","Validate/whitelist sourceType at your own API boundary before calling parse()."],"exampleFix":"// before\nparse(code, {sourceType: pkgType /* 'commonjs' or 'module' from package.json */});\n\n// after\nconst sourceType = pkgType === 'module' ? 'module' : 'script';\nparse(code, {sourceType});","handlingStrategy":"validation","validationCode":"const SOURCE_TYPES = new Set(['script', 'module', 'unambiguous']);\nfunction isValidSourceType(v) {\n  return v == null || SOURCE_TYPES.has(v);\n}","typeGuard":"function isSourceTypeOption(v) {\n  return v == null || v === 'script' || v === 'module' || v === 'unambiguous';\n}","tryCatchPattern":null,"preventionTips":["Map module-system names (esm/commonjs) to parser names (module/script) at the config layer.","Omit sourceType rather than passing '' when you want the default."],"tags":["flow","parser","options","validation","sourcetype"],"backgroundTag":"invalid-enum-value","analyzedSha":"5c865861998a8ccb7dbc82b0c1f511e9ef60c3d9","analyzedAt":"2026-08-20T10:41:37.992Z","contentChangedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}