{"record":{"id":"9b0049ce11a8d4a2","repo":"gatsbyjs/gatsby","slug":"babelpluginremovegraphqlqueries-the-exportname","errorCode":null,"errorMessage":"BabelPluginRemoveGraphQLQueries: the \"${exportName}\" export must be async when using it with graphql","messagePattern":"BabelPluginRemoveGraphQLQueries: the \"(.+?)\" export must be async when using it with graphql","errorType":"exception","errorClass":"ExportIsNotAsyncError","httpStatus":null,"severity":"error","filePath":"packages/babel-plugin-remove-graphql-queries/src/index.ts","lineNumber":620,"sourceCode":"        })\n        tagsToRemoveImportsFrom.forEach(removeImport)\n      },\n    },\n  }\n}\n\nfunction isWithinConfigExport(\n  path: NodePath<TaggedTemplateExpression>\n): boolean {\n  const parentExport = path.findParent(parent =>\n    parent.isExportNamedDeclaration()\n  ) as NodePath<ExportNamedDeclaration> | null\n\n  const declaration = parentExport?.node?.declaration\n\n  if (isFunctionDeclaration(declaration) && declaration.id?.name === `config`) {\n    if (!declaration.async) {\n      throw new ExportIsNotAsyncError(`config`, declaration.loc?.start)\n    }\n    return true\n  }\n  if (\n    isVariableDeclaration(declaration) &&\n    isIdentifier(declaration.declarations[0]?.id) &&\n    declaration.declarations[0]?.id?.name === `config`\n  ) {\n    const init = declaration.declarations[0]?.init\n    if (!isFunction(init) || !init.async) {\n      throw new ExportIsNotAsyncError(`config`, init?.loc?.start)\n    }\n    return true\n  }\n  return false\n}\n\nexport {","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/babel-plugin-remove-graphql-queries/src/index.ts#L602-L638","documentation":"Thrown by `ExportIsNotAsyncError` (index.ts:620) when the `config` export is a function declaration (`export function config()`) used together with a graphql tag, but the function is not declared `async`. Gatsby's compiler must await graphql results inside the config export, so async is mandatory. The error records `exportStart` for source mapping.","triggerScenarios":"Writing `export function config() { const x = graphql`...`; return {...} }` without the `async` keyword on the function declaration.","commonSituations":"Adopting the new file-based config (gatsby-config.ts / `config` export with graphql data fetching) and forgetting to mark the export async; converting a synchronous config to one that queries graphql.","solutions":["Add the `async` keyword: `export async function config() { ... }`.","Ensure any graphql tag inside the config export is awaited if needed."],"exampleFix":"// before\nexport function config() {\n  const data = graphql`query { site { buildTime } }`\n  return { ... }\n}\n\n// after\nexport async function config() {\n  const data = graphql`query { site { buildTime } }`\n  return { ... }\n}","handlingStrategy":"validation","validationCode":"function configExportIsAsyncFunction(declNode) {\n  return declNode.type === 'FunctionDeclaration' && declNode.id?.name === 'config' && declNode.async === true\n}","typeGuard":"function isAsyncFunctionDeclaration(node) {\n  return node?.type === 'FunctionDeclaration' && node.async === true\n}","tryCatchPattern":"try {\n  isWithinConfigExport(path)\n} catch (e) {\n  if (e instanceof ExportIsNotAsyncError) { /* add `async` to the export */ }\n}","preventionTips":["Always declare the config export as `async function config()` when it uses graphql.","Lint for non-async config exports that contain graphql tags."],"tags":["babel","graphql","config","async","typescript"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}