es-jest
raw JSON → 2.1.0 verified Fri May 01 auth: no javascript maintenance
es-jest is a preprocessor for Jest that uses esbuild to transform ESM, React JSX, and TypeScript files. Version 2.1.0 (latest, last released in 2021) is stable but in maintenance mode. It offers faster transformation than babel-jest or ts-jest by leveraging esbuild, and supports custom esbuild configurations. It can be used as a Jest preset or via a transform entry. Note that major Jest version updates may break compatibility; v2 requires Jest 26+.
Common errors
error Cannot find module 'es-jest' from 'jest.config.js' ↓
cause es-jest is not installed
fix
Run 'npm install es-jest --save-dev'.
error Jest preset "es-jest" not found. ↓
cause Jest cannot find the preset; incorrect config file type (e.g., using ESM for config)
fix
Use module.exports in a .js config file, or ensure preset path is correct.
error SyntaxError: Unexpected token 'export' ↓
cause Jest not using es-jest transform; file is not transpiled
fix
Configure transform or preset in jest config. Add 'transform': { '\\.js$': 'es-jest' }
error Error: Jest encountered an unexpected token. Jest failed to parse a file. ↓
cause Missing babel-jest or incorrect transform for non-code files (e.g., CSS, images)
fix
Add appropriate moduleNameMapper or transformIgnorePatterns.
Warnings
deprecated Package has not been updated since 2021; may be incompatible with newer Jest versions (>27). ↓
fix Consider using jest-light-runner or @jest/transform-esbuild for ongoing support.
gotcha When using custom transform entry, must escape regex or use string pattern correctly. ↓
fix Use double backslashes in JSON: '\\.(js|ts)x?$'
gotcha es-jest does not support TypeScript type checking; it only strips types. ↓
fix Use ts-jest or run tsc separately for type safety.
gotcha JSX automatic runtime requires esbuild >=0.14 and config option { jsx: 'automatic' } ↓
fix Ensure esbuild version meets requirements and pass options correctly.
Install
npm install es-jest yarn add es-jest pnpm add es-jest Imports
- es-jest wrong
import esJest from 'es-jest'correctconst esJest = require('es-jest') - preset wrong
import { preset } from 'es-jest'correctuse in jest config: 'preset': 'es-jest' - transform wrong
import { transform } from 'es-jest'correctuse in jest config as ['es-jest', options]
Quickstart
// jest.config.js
module.exports = {
preset: 'es-jest',
// optional custom esbuild config:
// transform: {
// '\\.(js|ts|jsx|tsx)$': ['es-jest', { jsx: 'automatic' }]
// }
}
// src/__tests__/example.test.js
import { sum } from '../sum';
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});