babel-jest

raw JSON →
30.3.0 verified Sat Apr 25 auth: no javascript

Jest plugin to use Babel for transformation of source files during testing. Current stable version is 30.3.0 (released 2025). It is part of the Jest monorepo and follows Jest's release cadence. Key differentiators: integrates tightly with Jest's transform pipeline, automatically picks up Babel configuration, supports custom transformers and presets, and is ESM-compatible. It is the recommended way to transpile modern JavaScript and TypeScript code in Jest tests when using Babel. Compared to alternative transformers like ts-jest, babel-jest is faster but does not perform type checking.

error Error: Jest: 'babel-jest' is not a valid transformer. Must be a function or an object with a 'process' method.
cause Using require() to import babel-jest in ESM-only mode, or misconfiguration in Jest transform.
fix
Ensure you are using import statements and that the transform is correctly set (e.g., use 'import babelJest from "babel-jest"').
error Cannot find module '@babel/core' from 'babel-jest'
cause Missing required peer dependency @babel/core.
fix
Run 'npm install --save-dev @babel/core' or 'yarn add --dev @babel/core'.
error TypeError: babelJest.createTransformer is not a function
cause Using an older version of babel-jest (pre-28) where createTransformer did not exist, or incorrect import.
fix
Upgrade to babel-jest v28+ and use 'import { createTransformer } from "babel-jest"'.
error SyntaxError: Cannot use import statement outside a module
cause Using ESM syntax in a CommonJS file without proper .mjs extension or 'type' module in package.json.
fix
Add 'type': 'module' to package.json, or rename file to .mjs, or use require syntax for CJS.
breaking babel-jest is now ESM-only starting from Jest 28. Using require() will throw an error.
fix Use import statements instead of require(). If you must use CommonJS, use dynamic import or upgrade your project to ESM.
breaking In Jest 30, the 'createTransformer' function returns a different object type. Some custom transform options may not work as before.
fix Review the changelog for Jest 30 and update custom transformers accordingly.
deprecated The default export (babelJest) is still supported but using createTransformer is preferred for explicit configuration.
fix Replace usage of default export with createTransformer for clarity and future-proofing.
gotcha babel-jest does not perform type checking. It only strips types when using TypeScript. For type checking, use ts-jest or run tsc separately.
fix Add a separate type check step in your CI or use the TypeScript compiler as a separate test.
npm install babel-jest
yarn add babel-jest
pnpm add babel-jest

Configures babel-jest as the transformer for .js/.ts files in Jest, using createTransformer with custom Babel presets.

// jest.config.js
import babelJest from 'babel-jest';

export default {
  transform: {
    '^.+\\.jsx?$': babelJest,
    '^.+\\.tsx?$': [
      babelJest.createTransformer({
        presets: [
          ['@babel/preset-env', { targets: { node: 'current' } }],
          '@babel/preset-typescript',
        ],
      }),
    ],
  },
};

// Alternatively, use the createTransformer function with custom options.
// This shows how to set up babel-jest for both JS and TS files.