jestjs/jest · error · Error
babel-jest: Babel ignores ${chalk.bold(slash(path.relative(c
Error message
babel-jest: Babel ignores ${chalk.bold(slash(path.relative(cwd, filename)))} - make sure to include the file in Jest's ${chalk.bold('transformIgnorePatterns')} as well. What it means
babel-jest throws this when Babel's loadPartialConfig (sync or async) returns null for a file Jest asked it to transform, meaning Babel itself decided to ignore that file. This happens when the file falls outside Babel's config scope (rootMode/babelrcRoots) or matches Babel's own ignore/exclude rules, so there is no config to transform with. The message points at Jest's transformIgnorePatterns because the usual intent is either to let Jest skip transforming that file or to widen Babel's config to cover it.
Source
Thrown at packages/babel-jest/src/index.ts:43
loadPartialConfigAsync,
loadPartialConfigSync,
} from './babel';
export interface TransformerConfig extends BabelTransformOptions {
excludeJestPreset?: boolean;
}
const THIS_FILE = fs.readFileSync(__filename);
const jestPresetPath = require.resolve('babel-preset-jest');
const babelIstanbulPlugin = require.resolve('babel-plugin-istanbul');
function assertLoadedBabelConfig(
babelConfig: Readonly<PartialConfig> | null,
cwd: string,
filename: string,
): asserts babelConfig {
if (!babelConfig) {
throw new Error(
`babel-jest: Babel ignores ${chalk.bold(
slash(path.relative(cwd, filename)),
)} - make sure to include the file in Jest's ${chalk.bold(
'transformIgnorePatterns',
)} as well.`,
);
}
}
function addIstanbulInstrumentation(
filename: string,
babelOptions: BabelTransformOptions,
transformOptions: JestTransformOptions,
): BabelTransformOptions {
if (transformOptions.instrument) {
const copiedBabelOptions: BabelTransformOptions = {
...babelOptions,
auxiliaryCommentBefore: ' istanbul ignore next ',View on GitHub (pinned to 8e6d128e4a)
Solutions
- If the file should NOT be transformed by babel-jest, add its path to Jest's `transformIgnorePatterns` so Jest never sends it to babel-jest.
- If the file SHOULD be transformed, ensure a Babel config applies to it: add/extend a `babel.config.js` at the project root or set `babelrcRoots` / `rootMode: 'upward'` in your babel-jest transformer options so the config reaches the file's directory.
- For monorepos, set Jest's `rootDir`/`roots` and Babel's `root`/`rootMode` consistently so the file resolves under the same Babel root.
- If using a custom transformer via `createTransformer`, pass `rootMode: 'upward'` in the babel-jest options (e.g. `transform: { '^.+\\.jsx?$': ['babel-jest', { rootMode: 'upward' }] }`).
Example fix
// before (jest.config.js)
module.exports = { transform: { '^.+\\.jsx?$': 'babel-jest' } };
// file in packages/foo ignored by root babel config -> error
// after (option A: let babel reach it)
module.exports = {
transform: {
'^.+\\.jsx?$': ['babel-jest', { rootMode: 'upward' }],
},
};
// after (option B: stop transforming the ignored path)
module.exports = {
transformIgnorePatterns: ['/node_modules/(?!(some-pkg)/)', 'packages/foo/ignored-dir'],
}; Defensive patterns
Strategy: validation
Validate before calling
// Before relying on babel-jest to transform a file, confirm Babel will not ignore it.
import {loadPartialConfigSync} from '@babel/core';
function babelWillTransform(filename, babelOptions) {
const cfg = loadPartialConfigSync({filename, ...babelOptions});
return cfg != null; // if false, expect the 'Babel ignores' error from babel-jest
}
// In jest.config, decide based on this:
const transform = babelWillTransform('src/odd.js', opts)
? {'^.+\\.jsx?$': 'babel-jest'}
: {'^.+\\.jsx?$': ['babel-jest', {rootMode: 'upward'}]}; Type guard
// Narrow a jest transform config so ignored paths are excluded up front.
function buildTransform(babelRoot, ignoredPaths) {
return {
'^.+\\.jsx?$': ['babel-jest', {root: babelRoot, rootMode: babelRoot ? 'root' : 'upward'}],
transformIgnorePatterns: ['/node_modules/', ...ignoredPaths],
};
} Try / catch
try {
// run a single throwaway transform to surface config issues early
require('babel-jest').createTransformer({rootMode: 'upward'}).process(source, filename, opts);
} catch (e) {
if (/Babel ignores/.test(e.message)) {
// adjust transformIgnorePatterns or babel rootMode, then retry
} else throw e;
} Prevention
- Keep Jest's `rootDir`/`roots` and Babel's `root`/`rootMode` aligned in monorepos.
- Set `rootMode: 'upward'` in babel-jest options when configs live above the package.
- Use `transformIgnorePatterns` deliberately for node_modules that must (or must not) be transformed.
- Add a smoke test that transforms one file per workspace to catch config-scope regressions in CI.
When it happens
Trigger: Jest's transform pipeline routes a source file to babel-jest (the file matched the `transform` regex and was not in `transformIgnorePatterns`), but `loadPartialConfigSync`/`loadPartialConfigAsync` from @babel/core returns null. Common when importing compiled ESM/CJS from node_modules that Jest is forced to transform, or when a file sits in a workspace whose babel.config.js does not apply (different `rootDir`, missing `babelrcRoots`).
Common situations: Monorepo workspaces where the root babel.config.js does not reach sibling packages; upgrading to Babel 7 with config files that use `rootMode: 'upward'` but jest config does not set it; importing third-party ESM packages published as `.mjs`/ESM that Jest must transform; a `.babelrc.json` with an `ignore` pattern that excludes the test file itself.
Related errors
- The name `${name}` was looked up in the Haste module map. It
- jest-haste-map: enableSymlinks config option was set, but is
- Could not find a "package.json" file in ${rootDir}
- Whoops! Two projects resolved to the same config path: ${cha
- Jest: Got error running ${moduleName} - ${modulePath}, reaso
AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10).
Data as JSON: /api/errors/84ed62ae9bffab11.
Report an issue: GitHub.