{"record":{"id":"2c075f2e1246eda8","repo":"facebook/relay","slug":"babelpluginrelay-expected-plugin-context-to-inclu","errorCode":null,"errorMessage":"BabelPluginRelay: Expected plugin context to include \"types\", but got:${String(context)}","messagePattern":"BabelPluginRelay: Expected plugin context to include \"types\", but got:(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/babel-plugin-relay/BabelPluginRelay.js","lineNumber":77,"sourceCode":"  opts?: RelayPluginOptions,\n  ...\n};\n\n/**\n * Using babel-plugin-relay with only the modern runtime?\n *\n *     {\n *       plugins: [\n *         \"relay\"\n *       ]\n *     }\n */\nmodule.exports = function BabelPluginRelay(context: {\n  types: $FlowFixMe,\n  ...\n}): any {\n  const {types: t} = context;\n  if (!t) {\n    throw new Error(\n      'BabelPluginRelay: Expected plugin context to include \"types\", but got:' +\n        String(context),\n    );\n  }\n\n  const visitor = {\n    TaggedTemplateExpression(path: any, state: BabelState) {\n      // Convert graphql`` literals\n      const ast = getValidGraphQLTag(path);\n      if (ast) {\n        compileGraphQLTag(t, path, state, ast);\n        return;\n      }\n    },\n  };\n\n  return {","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/facebook/relay/blob/668b1b85e06261aa3b58dabfc51f8b5524a70955/packages/babel-plugin-relay/BabelPluginRelay.js#L59-L95","documentation":"BabelPluginRelay is a Babel plugin, and Babel passes a plugin context object containing the compiler 'types' builder (t) used to construct AST nodes. The plugin destructures context.types and throws this error if it is falsy. This means the plugin was invoked outside a proper Babel plugin environment, or the Babel version's context shape is incompatible with what the plugin expects.","triggerScenarios":"Babel loads the plugin without a valid plugin context (e.g. context is undefined/null or an object without a 'types' property), such as when the plugin is misconfigured, invoked programmatically with a hand-made context, or run under an incompatible Babel version that does not supply 'types' in the plugin state.","commonSituations":"Manually calling the plugin in a script with a stub context; using an ancient/newer Babel major version with an incompatible babel-plugin-relay; double-wrapping the plugin so it receives the wrong argument; registering the plugin in a non-Babel transform pipeline (e.g. a bundler loader that calls plugins directly).","solutions":["Verify the plugin is declared in babel config as 'babel-plugin-relay' or 'relay' and not invoked manually with a custom context object","Check Babel version compatibility: ensure @babel/core is a supported version (>=7) and babel-plugin-relay matches your relay version","Remove any wrapper code that calls BabelPluginRelay() directly with a non-standard context","Reinstall node_modules to rule out duplicate/mismatched babel packages"],"exampleFix":"// before (manual invocation)\nconst plugin = require('babel-plugin-relay');\nplugin({ /* stub context without types */ });\n\n// after (proper babel config)\n// babel.config.js\nmodule.exports = { plugins: ['babel-plugin-relay'] };","handlingStrategy":"validation","validationCode":"function assertBabelPluginContext(context) {\n  if (!context || typeof context !== 'object' || !context.types) {\n    throw new Error(\n      'babel-plugin-relay requires a Babel plugin context with `types`',\n    );\n  }\n  return context;\n}","typeGuard":"const hasTypes = (context) =>\n  typeof context === 'object' && context !== null && !!context.types;","tryCatchPattern":null,"preventionTips":["Register babel-plugin-relay only via standard Babel config, never call it manually","Keep @babel/core and babel-plugin-relay versions compatible and in sync","After Babel upgrades, run the build once to confirm plugins receive expected context"],"tags":["babel","build-time","configuration","relay"],"backgroundTag":"invalid-babel-plugin-config","analyzedSha":"668b1b85e06261aa3b58dabfc51f8b5524a70955","analyzedAt":"2026-09-02T19:57:20.783Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}