{"id":"6c64ca940398aa0f","repo":"babel/babel","slug":"config-file-contains-no-configuration-data","errorCode":null,"errorMessage":"Config file contains no configuration data","messagePattern":"Config file contains no configuration data","errorType":"exception","errorClass":"ConfigError","httpStatus":null,"severity":"error","filePath":"packages/babel-core/src/config/files/configuration.ts","lineNumber":318,"sourceCode":"  }, previousConfig);\n\n  if (config) {\n    debug(\"Found configuration %o from %o.\", config.filepath, dirname);\n  }\n  return config;\n}\n\nexport function* loadConfig(\n  name: string,\n  dirname: string,\n  envName: string,\n  caller: CallerMetadata | undefined,\n): Handler<ConfigFile> {\n  const filepath = require.resolve(name, { paths: [dirname] });\n\n  const conf = yield* readConfig(filepath, envName, caller);\n  if (!conf) {\n    throw new ConfigError(\n      `Config file contains no configuration data`,\n      filepath,\n    );\n  }\n\n  debug(\"Loaded config %o from %o.\", name, dirname);\n  return conf;\n}\n\n/**\n * Read the given config file, returning the result. Returns null if no config was found, but will\n * throw if there are parsing errors while loading a config.\n */\nfunction readConfig(\n  filepath: string,\n  envName: string,\n  caller: CallerMetadata | undefined,\n): Handler<ConfigFile | null> {","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/babel/babel/blob/06b6eae39da4ce0689fad64e2c48a6375a464208/packages/babel-core/src/config/files/configuration.ts#L300-L336","documentation":"loadConfig resolves a config by name (via require.resolve) and then reads it; if readConfig returns null (the file exists but contains no recognized config - e.g. an empty default export, or an extension that resolved to an empty parse), loadConfig throws 'Config file contains no configuration data'. This path is used when a config is explicitly referenced by name (e.g. BABEL_SHOW_CONFIG_FOR or programmatic configFile option pointing at a module).","triggerScenarios":"Pointing the `configFile` option or a programmatic load at a module that exports nothing (module.exports = undefined), exports an empty object that readConfigCode rejects, or a JS config whose factory returns null. Also when require.resolve finds a file but its content does not yield a config.","commonSituations":"Setting `configFile: './babel.config.js'` where that file is empty or exports undefined; config file left as a stub during scaffolding; circular/failed default export.","solutions":["Open the config file referenced in the error and ensure it exports a non-empty config object or a function returning one.","If the file is a stub, populate it with at least { presets: [] } or remove the configFile option so Babel does not load it.","Verify the default export path (export default {...} for ESM, module.exports = {...} for CJS)."],"exampleFix":"// before - babel.config.js throws error 28\nmodule.exports = undefined;\n\n// after\nmodule.exports = {\n  presets: ['@babel/preset-env'],\n};","handlingStrategy":"validation","validationCode":"const cfg = require(path.resolve('babel.config.js'));\nconst resolved = typeof cfg === 'function' ? cfg({ cache: () => {}, env: () => 'development' }) : cfg;\nif (!resolved || (typeof resolved !== 'object')) {\n  throw new Error('babel.config.js exports no configuration data');\n}","typeGuard":"function hasConfigData(value: unknown): value is Record<string, unknown> {\n  return value != null && typeof value === 'object' && !Array.isArray(value);\n}","tryCatchPattern":"try { babel.loadOptionsSync({ configFile: './babel.config.js' }); }\ncatch (err) {\n  if (/Config file contains no configuration data/.test(err.message)) {\n    console.error(err.filename, 'exports undefined/null - add a default export');\n  }\n  throw err;\n}","preventionTips":["Always export a non-empty object from config files.","Avoid stub config files; populate or delete them.","Smoke-test the config export in CI before invoking Babel."],"tags":["config","empty-config","validation"],"analyzedSha":"06b6eae39da4ce0689fad64e2c48a6375a464208","analyzedAt":"2026-08-03T20:13:43.465Z","schemaVersion":2}