{"record":{"id":"7070b596d8dd1143","repo":"facebook/relay","slug":"babel-state-is-missing-expected-file-name","errorCode":null,"errorMessage":"Babel state is missing expected file name","messagePattern":"Babel state is missing expected file name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/babel-plugin-relay/compileGraphQLTag.js","lineNumber":247,"sourceCode":"    t.memberExpression(t.identifier('console'), t.identifier('error')),\n    [\n      t.stringLiteral(\n        `The definition of '${definitionName}' appears to have changed. Run ` +\n          '`' +\n          buildCommand +\n          '` to update the generated files to receive the expected data.',\n      ),\n    ],\n  );\n}\n\nfunction getRelativeImportPath(\n  state: BabelState,\n  artifactDirectory: string,\n  fileToRequire: string,\n): string {\n  if (state.file == null) {\n    throw new Error('Babel state is missing expected file name');\n  }\n  const filename = state.file.opts.filename;\n\n  const relative = relativePath(\n    dirname(filename),\n    resolvePath(artifactDirectory),\n  );\n\n  const relativeReference =\n    relative.length === 0 || !relative.startsWith('.') ? './' : '';\n\n  return relativeReference + joinPath(relative, fileToRequire);\n}\n\nmodule.exports = compileGraphQLTag;\n","sourceCodeStart":229,"sourceCodeEnd":263,"githubUrl":"https://github.com/facebook/relay/blob/668b1b85e06261aa3b58dabfc51f8b5524a70955/packages/babel-plugin-relay/compileGraphQLTag.js#L229-L263","documentation":"getRelativeImportPath needs the current source file's path (state.file.opts.filename) to compute a relative require path from the file to the generated artifact directory. If state.file is null the Babel state is malformed, so the plugin cannot determine where the importing file lives and throws. This is an environment/tooling failure, not a user GraphQL mistake.","triggerScenarios":"Babel invokes the plugin with a state lacking state.file — e.g. custom transform scripts calling the plugin programmatically, some plugin-ordering or caching setups, or tools that fabricate a minimal state without file metadata.","commonSituations":"Custom Babel wrappers or AST transformers (e.g. codegen tools) that call the plugin with a synthetic state; newer/older Babel versions where state.file shape changed; running transforms outside the normal @babel/core pipeline.","solutions":["Ensure transforms run through @babel/core's normal pipeline so state.file is populated","If invoking programmatically, construct a proper state including file and file.opts.filename","Update babel-plugin-relay and @babel/core to compatible versions","Check other Babel plugins that mutate or strip state.file earlier in the plugin list"],"exampleFix":"// before (custom transform with bare state)\nplugin({ types: t }, { file: null });\n\n// after (transform via @babel/core)\nrequire('@babel/core').transform(code, {\n  filename: '/project/src/Component.js',\n  plugins: ['babel-plugin-relay'],\n});","handlingStrategy":"validation","validationCode":"function assertBabelStateHasFile(state) {\n  if (!state || !state.file || !state.file.opts || !state.file.opts.filename) {\n    throw new Error('Babel state must include file.opts.filename for babel-plugin-relay');\n  }\n}","typeGuard":"const hasFileState = (state) =>\n  !!state && !!state.file && !!state.file.opts && typeof state.file.opts.filename === 'string';","tryCatchPattern":null,"preventionTips":["Run all transforms through the standard @babel/core pipeline","When scripting transforms, always pass filename in babel transform options","Keep Babel and plugin versions aligned to avoid state shape changes"],"tags":["babel","build-time","configuration","relay","tooling"],"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"}