babel/babel · error · ConfigError
Negation of file paths is not supported.
Error message
Negation of file paths is not supported.
What it means
The readIgnoreConfig loader parses a .babelignore file line by line, strips comments and blank lines, then iterates the patterns. If any pattern begins with '!' (gitignore-style negation), Babel throws a ConfigError because Babel's ignore matching is unidirectional - it does not support re-including previously ignored files. This is a deliberate limitation of the pathPatternToRegex-based matcher.
Source
Thrown at packages/babel-core/src/config/files/configuration.ts:200
delete options.$schema;
return {
filepath,
dirname: path.dirname(filepath),
options,
};
});
const readIgnoreConfig = makeStaticFileCache((filepath, content) => {
const ignoreDir = path.dirname(filepath);
const ignorePatterns = content
.split("\n")
.map(line => line.replace(/^#.*$/, "").trim())
.filter(Boolean);
for (const pattern of ignorePatterns) {
if (pattern.startsWith("!")) {
throw new ConfigError(
`Negation of file paths is not supported.`,
filepath,
);
}
}
return {
filepath,
dirname: path.dirname(filepath),
ignore: ignorePatterns.map(pattern =>
pathPatternToRegex(pattern, ignoreDir),
),
};
});
export function findConfigUpwards(rootDir: string): string | null {
let dirname = rootDir;
for (;;) {View on GitHub (pinned to 06b6eae39d)
Solutions
- Remove all lines starting with '!' from .babelignore; Babel ignore is additive only.
- Restructure ignore patterns so that the file you wanted to re-include is simply not matched by any ignore pattern (use more specific exclude patterns instead).
- If you need conditional inclusion logic, use the per-file `ignore`/`only` functions in babel.config.js instead of .babelignore.
Example fix
// before - .babelignore throws error 26 build/ !src/runtime.js // after - no negation; narrow the ignore instead build/ src/generated/
Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs');
if (fs.existsSync('.babelignore')) {
const lines = fs.readFileSync('.babelignore', 'utf8').split('\n');
const negated = lines.filter(l => l.replace(/#.*/, '').trim().startsWith('!'));
if (negated.length) throw new Error('.babelignore does not support negation: ' + negated.join(', '));
} Type guard
function hasNoNegation(patterns: string[]): boolean {
return patterns.every(p => !p.trim().startsWith('!'));
} Try / catch
try { babel.transformFileSync(file); }
catch (err) {
if (/Negation of file paths is not supported/.test(err.message)) {
console.error('Remove lines starting with ! from', err.filename);
}
throw err;
} Prevention
- Treat .babelignore as additive-only; do not reuse .gitignore with negations.
- For conditional inclusion, use the `ignore` function option in babel.config.js.
- Lint .babelignore in CI for leading-! lines.
When it happens
Trigger: A .babelignore file containing a line such as `!src/keep.js` intended to un-ignore a file that an earlier pattern excluded.
Common situations: Developers familiar with .gitignore syntax who try to reuse negation patterns in .babelignore; migrating a .gitignore to .babelignore by copy-paste.
Related errors
- .babel property must be an object
- No config detected
- Config returned typeof ${typeof options}
- Expected config object but found array
- Config file contains no configuration data
AI-assisted analysis of babel/babel@06b6eae39d (2026-08-03).
Data as JSON: /data/errors/87cebbc758ddc3b2.json.
Report an issue: GitHub.