{"record":{"id":"cf1bae77a0159ed9","repo":"gatsbyjs/gatsby","slug":"availableflags-option-needs-to-be-set","errorCode":null,"errorMessage":"availableFlags option needs to be set","messagePattern":"availableFlags option needs to be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/babel-preset-gatsby-package/lib/babel-transform-compiler-flags.js","lineNumber":33,"sourceCode":" */\n\n/**\n *\n * @param {{ types: BabelTypes }} args\n * @param {Partial<IPluginOptions>} opts\n * @returns {PluginObj}\n */\nmodule.exports = function compilerFlags(\n  {\n    types: t,\n  },\n  opts\n) {\n  if (!opts.flags) {\n    throw new Error(`flags option needs to be set`)\n  }\n  if (!opts.availableFlags) {\n    throw new Error(`availableFlags option needs to be set`)\n  }\n\n  return {\n    name: `babel-transform-compiler-flags`,\n    visitor: {\n      /**\n       * @param {NodePath} nodePath\n       * @param {PluginPass} state\n       */\n      Identifier(\n        nodePath,\n        state\n      ) {\n        const identifier = /** @type {Identifier} */ (nodePath.node)\n        const flags = /** @type {IPluginOptions} */ (state.opts).flags\n        const availableFlags = /** @type {IPluginOptions} */ (state.opts).availableFlags\n\n        if (","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/babel-preset-gatsby-package/lib/babel-transform-compiler-flags.js#L15-L51","documentation":"Thrown by `babel-transform-compiler-flags` (babel-transform-compiler-flags.js:33) when `opts.availableFlags` is falsy. The plugin uses `availableFlags` as the whitelist of allowed `_CFLAGS_.<name>` accesses; without it, any unknown flag would silently resolve to empty string, so it fails fast at setup.","triggerScenarios":"Passing `{ flags: {...} }` without `availableFlags`; passing a null/undefined `availableFlags`; miswiring the preset so only `flags` is forwarded.","commonSituations":"Configuring the plugin manually and missing the whitelist; refactoring the preset and dropping the availableFlags plumbing.","solutions":["Pass `availableFlags` as an array of allowed flag names: `{ availableFlags: ['PRESERVE_FILE_DOWNLOADS', '...'] }`.","Keep `availableFlags` in sync with the keys that appear in source as `_CFLAGS_.*`.","Generate `availableFlags` from the same source the flags map is derived from."],"exampleFix":"// before\ncompilerFlags({ types: t }, { flags: { A: '1' } })\n\n// after\ncompilerFlags({ types: t }, {\n  flags: { A: '1' },\n  availableFlags: ['A'],\n})","handlingStrategy":"validation","validationCode":"function pluginHasAvailableFlagsOption(opts) {\n  return Boolean(opts && Array.isArray(opts.availableFlags))\n}","typeGuard":"/** @returns {opts is { availableFlags: string[] }} */\nfunction hasAvailableFlags(opts) {\n  return opts != null && Array.isArray(opts.availableFlags)\n}","tryCatchPattern":null,"preventionTips":["Pass availableFlags as an array covering every `_CFLAGS_.*` reference in source.","Keep availableFlags and the flags object keys consistent.","Fail fast in your own build setup if these options are missing."],"tags":["babel","config","flags","compiler"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}