jestjs/jest · error · Error

babel-jest: Babel ignores ${slash(path.relative(cwd, filenam

Error message

babel-jest: Babel ignores ${slash(path.relative(cwd, filename))} - make sure to include the file in Jest's transformIgnorePatterns as well.

What it means

babel-jest delegates transformation to Babel by calling loadPartialConfigSync/Async; when Babel's config resolution returns null it means Babel itself has decided to ignore that file (no applicable babel.config.js/babelrc, or an `ignore`/`only` rule excluded it). Because babel-jest cannot produce transformed output without a Babel config, assertLoadedBabelConfig throws to tell you the file Jest asked it to transform is invisible to Babel. The message points at transformIgnorePatterns because the usual resolution is to make Jest stop asking babel-jest to transform that file.

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 f49721c78e)

Solutions

  1. Add the file path/pattern to Jest's transformIgnorePatterns so Jest stops trying to transform it (default already ignores node_modules; narrow or widen as needed).
  2. Ensure a Babel config (babel.config.js or .babelrc) actually applies to the file: check `rootMode`, `babelrcRoots`, and that the file is under a covered directory.
  3. If you do want the file transformed, pass explicit babelOptions via the transformer config in jest.config.js so Babel does not return null.
  4. Verify with `npx babel <file>` (or `babel --show-config <file>`) that Babel sees a config for that path; if it prints an empty config, that confirms the ignore.

Example fix

// before (jest.config.js) — file under packages/foo is ignored by Babel
export default { transform: { '^.+\\.jsx?$': 'babel-jest' } };

// after — tell Jest not to transform the problematic path, OR cover it with Babel
export default {
  transform: { '^.+\\.jsx?$': 'babel-jest' },
  transformIgnorePatterns: ['/node_modules/', 'packages/legacy/'],
}
// and in babel.config.js make sure the root covers all packages:
// module.exports = { rootMode: 'upward-optional' };
Defensive patterns

Strategy: validation

Validate before calling

const rel = path.relative(jestConfig.rootDir, filename);
const isIgnoredByJest = (jestConfig.transformIgnorePatterns ?? []).some(p =>
  new RegExp(p).test(rel),
);
// Before relying on babel-jest, ensure Babel actually sees the file:
const {loadPartialConfigSync} = require('@babel/core');
const cfg = loadPartialConfigSync({ filename, cwd: jestConfig.rootDir, rootMode: 'upward' });
if (cfg === null && !isIgnoredByJest) {
  throw new Error(`babel-jest would throw on ${filename}; add it to transformIgnorePatterns or extend Babel config.`);
}

Type guard

// n/a — configuration-level error, not a value-shape problem

Try / catch

try {
  transformer.process(sourceText, sourcePath, opts);
} catch (e) {
  if (/babel-jest: Babel ignores/.test(String(e?.message))) {
    // Add sourcePath to transformIgnorePatterns or extend Babel config, then retry.
  }
  throw e;
}

Prevention

When it happens

Trigger: Jest's transform mapping routes a file to babel-jest (e.g. the default .js/.jsx transform, or a custom transform entry), and Babel's loadPartialConfigSync returns null for that filename. Common concrete triggers: a file outside the Babel rootMode/upward search range, a babel.config.js with an `ignore` glob that catches the file, a monorepo package lacking a babelrc while rootMode:'upward' cannot find the root config, or a node_modules source file that Jest is transforming because transformIgnorePatterns was widened.

Common situations: Monorepos where one package has a .babelrc and another doesn't; upgrading Babel 6->7 and forgetting babel.config.js; setting `transform` to babel-jest for .ts/.tsx without @babel/preset-typescript installed; ESM projects where `type:module` plus a misconfigured babel config makes Babel skip files; CI builds that differ from local because a babel plugin is in devDependencies and was hoisted differently.

Related errors


AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03). Data as JSON: /data/errors/01c0ce311f419873.json. Report an issue: GitHub.