babel/babel · error · ConfigError
Config file contains no configuration data
Error message
Config file contains no configuration data
What it means
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).
Source
Thrown at packages/babel-core/src/config/files/configuration.ts:318
}, previousConfig);
if (config) {
debug("Found configuration %o from %o.", config.filepath, dirname);
}
return config;
}
export function* loadConfig(
name: string,
dirname: string,
envName: string,
caller: CallerMetadata | undefined,
): Handler<ConfigFile> {
const filepath = require.resolve(name, { paths: [dirname] });
const conf = yield* readConfig(filepath, envName, caller);
if (!conf) {
throw new ConfigError(
`Config file contains no configuration data`,
filepath,
);
}
debug("Loaded config %o from %o.", name, dirname);
return conf;
}
/**
* Read the given config file, returning the result. Returns null if no config was found, but will
* throw if there are parsing errors while loading a config.
*/
function readConfig(
filepath: string,
envName: string,
caller: CallerMetadata | undefined,
): Handler<ConfigFile | null> {View on GitHub (pinned to 06b6eae39d)
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).
Example fix
// before - babel.config.js throws error 28
module.exports = undefined;
// after
module.exports = {
presets: ['@babel/preset-env'],
}; Defensive patterns
Strategy: validation
Validate before calling
const cfg = require(path.resolve('babel.config.js'));
const resolved = typeof cfg === 'function' ? cfg({ cache: () => {}, env: () => 'development' }) : cfg;
if (!resolved || (typeof resolved !== 'object')) {
throw new Error('babel.config.js exports no configuration data');
} Type guard
function hasConfigData(value: unknown): value is Record<string, unknown> {
return value != null && typeof value === 'object' && !Array.isArray(value);
} Try / catch
try { babel.loadOptionsSync({ configFile: './babel.config.js' }); }
catch (err) {
if (/Config file contains no configuration data/.test(err.message)) {
console.error(err.filename, 'exports undefined/null - add a default export');
}
throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- .babel property must be an object
- No config detected
- Config returned typeof ${typeof options}
- Expected config object but found array
- Negation of file paths is not supported.
AI-assisted analysis of babel/babel@06b6eae39d (2026-08-03).
Data as JSON: /data/errors/6c64ca940398aa0f.json.
Report an issue: GitHub.