esbuild-jest
raw JSON → 0.5.0 verified Mon Apr 27 auth: no javascript
Jest transformer that uses esbuild for fast compilation of TypeScript, JavaScript, TSX, and JSX files. Current stable version is 0.5.0. Released as needed, with esbuild >=0.8.50 as peer dependency. Differentiators: significantly faster than ts-jest by leveraging esbuild's speed, but lacks type checking and some advanced TypeScript features. Ships TypeScript types.
Common errors
error Cannot find module 'esbuild-jest' from 'jest.config.js' ↓
cause esbuild-jest not installed or esbuild peer dependency missing.
fix
npm install --save-dev esbuild-jest esbuild
error TypeError: esbuildJest is not a function ↓
cause Using named import Options as a function.
fix
Use default import for transformer: import esbuildJest from 'esbuild-jest'
error Jest encountered an unexpected token (tsx file) ↓
cause Transform regex does not match .tsx files.
fix
Update regex to '^.+\\.(t|j)sx?$' in jest config
Warnings
gotcha esbuild-jest does not perform type checking, only transpilation. ↓
fix Run tsc --noEmit separately or use a type-checked alternative like ts-jest.
gotcha esbuild-jest is not maintained as actively as alternatives; consider @swc/jest or ts-jest for production. ↓
fix Switch to @swc/jest or ts-jest.
deprecated The package is no longer actively maintained. ↓
fix Migrate to @swc/jest or ts-jest.
Install
npm install esbuild-jest yarn add esbuild-jest pnpm add esbuild-jest Imports
- default export (transformer)
import esbuildJest from 'esbuild-jest' - Options interface wrong
import { Options } from 'esbuild-jest' (runtime error, type-only)correctimport type { Options } from 'esbuild-jest' - require with CreateTransformerOptions? wrong
const { default } = require('esbuild-jest')correctconst transformer = require('esbuild-jest')
Quickstart
// jest.config.js
module.exports = {
transform: {
'^.+\\.(t|j)sx?$': ['esbuild-jest', { sourcemap: true }]
}
};
// your.test.ts
import { sum } from './sum';
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});