{"id":"5bbc8846ef75902c","repo":"babel/babel","slug":"the-annexb-option-can-only-be-set-to-false","errorCode":null,"errorMessage":"The `annexB` option can only be set to `false`.","messagePattern":"The `annexB` option can only be set to `false`\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/babel-parser/src/options.ts","lineNumber":259,"sourceCode":"    // When enabled, the parser will support Annex B syntax.\n    // https://tc39.es/ecma262/#sec-additional-ecmascript-features-for-web-browsers\n    annexB: true,\n  };\n}\n\n// Interpret and default an options object\n\nexport function getOptions(opts?: Options | null): OptionsWithDefaults {\n  // https://github.com/babel/babel/pull/16918\n  // `options` is accessed frequently, please make sure it is a fast object.\n  // `%ToFastProperties` can make it a fast object, but the performance is the same as the slow object.\n  const options: any = createDefaultOptions();\n\n  if (opts == null) {\n    return options;\n  }\n  if (opts.annexB != null && opts.annexB !== false) {\n    throw new Error(\"The `annexB` option can only be set to `false`.\");\n  }\n\n  for (const key of Object.keys(options) as (keyof Options)[]) {\n    if (opts[key] != null) options[key] = opts[key];\n  }\n\n  if (options.startLine === 1) {\n    if (opts.startIndex == null && options.startColumn > 0) {\n      options.startIndex = options.startColumn;\n    } else if (opts.startColumn == null && options.startIndex > 0) {\n      options.startColumn = options.startIndex;\n    }\n  } else if (opts.startColumn == null || opts.startIndex == null) {\n    throw new Error(\n      \"With a `startLine > 1` you must also specify `startIndex` and `startColumn`.\",\n    );\n  }\n","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/babel/babel/blob/06b6eae39da4ce0689fad64e2c48a6375a464208/packages/babel-parser/src/options.ts#L241-L277","documentation":"This Error is thrown by getOptions() in @babel/parser when normalizing options. The `annexB` option defaults to true (Annex B web-browser syntax is on); Babel only allows opting out, so any value that is not exactly `false` (true, truthy strings, numbers, objects) is rejected with 'The `annexB` option can only be set to `false`.' It prevents ambiguous enablement of an already-default feature.","triggerScenarios":"Passing `{ annexB: true }`, `{ annexB: 'yes' }`, `{ annexB: 1 }`, or `{ annexB: {} }` to parse()/parseExpression() options. The check is `opts.annexB != null && opts.annexB !== false`.","commonSituations":"Generated config that sets every boolean option to true; migrating from a tool that accepted annexB as a string; copying options objects and flipping flags wholesale; a wrapper that defaults missing booleans to true.","solutions":["Omit annexB entirely (defaults to true), or set it to `false` to disable Annex B syntax.","Sanitize boolean options to undefined when they should use the default.","Fix the option producer so it only emits annexB when the user explicitly disabled it."],"exampleFix":"// before\nparse(code, { annexB: true }); // throws\n\n// after\nparse(code, {}); // annexB defaults to true\n// or, to disable Annex B:\nparse(code, { annexB: false });","handlingStrategy":"validation","validationCode":"const opts = { ...userOpts };\nif ('annexB' in opts && opts.annexB !== false) {\n  delete opts.annexB; // rely on default (true)\n}\nparse(code, opts);","typeGuard":"const isAnnexBOption = (v: unknown): boolean => v === undefined || v === false;","tryCatchPattern":null,"preventionTips":["Only set annexB to false (to disable) or omit it (defaults true).","Do not blanket-set boolean parser options to true.","Validate generated option objects before passing to parse()."],"tags":["babel-parser","options","annexb","config"],"analyzedSha":"06b6eae39da4ce0689fad64e2c48a6375a464208","analyzedAt":"2026-08-03T20:13:43.465Z","schemaVersion":2}