gatsbyjs/gatsby · error
${cFlag} is not part of the available compiler flags.
Error message
${cFlag} is not part of the available compiler flags. What it means
Thrown by the Identifier visitor of `babel-transform-compiler-flags` (babel-transform-compiler-flags.js:59). When source code references `_CFLAGS_.<cFlag>`, the plugin checks `availableFlags.includes(cFlag)`; if the accessed flag name is not on the whitelist, the build aborts to prevent silently replacing it with an empty string.
Source
Thrown at packages/babel-preset-gatsby-package/lib/babel-transform-compiler-flags.js:59
* @param {PluginPass} state
*/
Identifier(
nodePath,
state
) {
const identifier = /** @type {Identifier} */ (nodePath.node)
const flags = /** @type {IPluginOptions} */ (state.opts).flags
const availableFlags = /** @type {IPluginOptions} */ (state.opts).availableFlags
if (
identifier.name === `_CFLAGS_` &&
t.isMemberExpression(nodePath.parent)
) {
const parentNode = /** @type {MemberExpression} */ (nodePath.parent)
const cFlag = /** @type {Identifier} */ (parentNode.property).name
if (!availableFlags.includes(cFlag)) {
throw new Error(
`${cFlag} is not part of the available compiler flags.`
)
}
nodePath.parentPath.replaceWith(
t.stringLiteral(flags[cFlag] ? flags[cFlag] : ``)
)
}
},
},
}
}
View on GitHub (pinned to 8b06340921)
Solutions
- Add the missing flag name to the `availableFlags` array in the plugin/preset options.
- Check for typos: the name after `_CFLAGS_.` must exactly match an entry in `availableFlags`.
- Remove the `_CFLAGS_.<flag>` reference if the flag is no longer used.
Example fix
// before
// source: if (_CFLAGS_.ENABLE_X) { ... }
// config: availableFlags: ['PRESERVE_FILE_DOWNLOADS']
// after
// config:
availableFlags: ['PRESERVE_FILE_DOWNLOADS', 'ENABLE_X'] Defensive patterns
Strategy: validation
Validate before calling
function allCflagRefsAreListed(sourceFiles, availableFlags) {
const used = new Set()
for (const src of sourceFiles) {
for (const m of src.matchAll(/_CFLAGS_\.([A-Za-z0-9_]+)/g)) used.add(m[1])
}
return [...used].filter(f => !availableFlags.includes(f))
} Type guard
function isKnownFlag(flagName, availableFlags) {
return Array.isArray(availableFlags) && availableFlags.includes(flagName)
} Prevention
- Keep the availableFlags array in sync with `_CFLAGS_.*` references in source.
- Generate availableFlags from a single source of truth.
- Add a pre-build check that greps for unknown flags.
When it happens
Trigger: Source code contains `_CFLAGS_.NEW_THING` but `NEW_THING` is not listed in `availableFlags`; renaming a flag in code but not in the build config; copy-pasting code that references a flag the build does not know about.
Common situations: Adding a new compiler flag to source without updating the preset's `availableFlags` list; using a flag only defined in a different build configuration; typos in the flag name on either side.
Related errors
- flags option needs to be set
- availableFlags option needs to be set
- keepDynamicImports option needs to be set
- BabelPluginRemoveGraphQLQueries: String interpolations are n
- BabelPluginRemoveGraphQLQueries: Unexpected empty graphql ta
AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13).
Data as JSON: /api/errors/ceadd585c23c99a8.
Report an issue: GitHub.