babel-preset-jest

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

Babel preset for Jest, part of the Jest monorepo. Current version 30.3.0, released as part of Jest 30. This preset automatically configures Babel plugins needed for Jest to work with your code (e.g., transforms for ES modules, JSX, and TypeScript). Relies on @babel/core (peer dep) and babel-jest. Key differentiator: it's the official Jest preset, ensuring compatibility with Jest's internal module transformation. Actively maintained with frequent releases alongside Jest. Not to be used standalone; instead used via babel-jest or jest config.

error Error: Requires Babel "^7.0.0-0", but was loaded with "8.0.0"
cause babel-preset-jest requires @babel/core version 7 or 8 beta, but you have version 8 stable installed.
fix
Install @babel/core@^7.11.0: npm install --save-dev @babel/core@^7.11.0
error Module not found: Can't resolve 'babel-jest'
cause Missing babel-jest dependency when using jest's default babel transform.
fix
Install babel-jest: npm install --save-dev babel-jest
error Jest: `babel-jest` is required for using the `.babelrc` or `babel.config.js` files. Install it: npm install --save-dev babel-jest
cause babel-jest is not installed but Jest is trying to use Babel transforms.
fix
Install babel-jest: npm install --save-dev babel-jest
breaking Jest 30 dropped support for Node 16 and 18 (prior to 18.14), requiring Node >=18.14.
fix Upgrade Node to >=18.14.0
breaking Jest 30 changed the default transform from babel-jest to a new runtime, but babel-preset-jest can still be used. If you rely on automatic Babel integration, you may need to explicitly configure `transform` in jest config.
fix In jest.config.js: transform: { '^.+\\.jsx?$': 'babel-jest' }
gotcha babel-preset-jest is not imported directly; it's used via Babel config string 'jest' or automatically by babel-jest. Trying to import it as a module will not work.
fix Use 'jest' as a string in presets array, or rely on babel-jest.
deprecated In older Jest versions (<29), babel-preset-jest included @babel/plugin-transform-modules-commonjs by default. Starting from Jest 29, this plugin is no longer automatically added; you must install and configure it explicitly if needed.
fix Install @babel/plugin-transform-modules-commonjs and add to your babel.config.js plugins array.
npm install babel-preset-jest
yarn add babel-preset-jest
pnpm add babel-preset-jest

Shows how to configure Jest with babel-preset-jest in Babel config and how to let babel-jest apply it automatically.

// Install: npm install --save-dev babel-preset-jest @babel/core
// In babel.config.js:
module.exports = {
  presets: ['@babel/preset-env', 'jest']
};
// Or in jest.config.js:
module.exports = {
  transform: {
    '^.+\\.jsx?$': 'babel-jest',
  },
  // The preset is automatically applied when using babel-jest
};