Skip to content
Latchkey

Angular Jest "jest-preset-angular" configuration errors in CI

Teams that replace karma with Jest use jest-preset-angular. In CI it fails when the preset, the setup file, the ESM transform, or the zone.js import is missing, so the suite cannot even initialize the testing environment.

What this error means

jest fails at startup with "Cannot find module 'jest-preset-angular'", a transform error on an Angular ESM package, or "Zone is needed" because zone.js was not imported in setup.

jest
Test suite failed to run
Cannot find module 'jest-preset-angular/setup-env/setup.mjs' from 'setup-jest.ts'

Common causes

Missing preset or setup file wiring

jest.config is not pointing at jest-preset-angular or the setup file that initializes the Angular TestBed and zone.js.

Untransformed Angular ESM packages

Angular ships ESM; without transformIgnorePatterns allowing @angular to be transformed, Jest chokes on the syntax.

How to fix it

Wire the preset, setup, and transform

Point Jest at the preset and setup file, and allow @angular packages through the transform.

jest.config.js
module.exports = {
  preset: 'jest-preset-angular',
  setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
  transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$|@angular)']
};

Initialize the Angular test environment

Import the preset setup so zone.js and the TestBed environment are ready.

setup-jest.ts
import 'jest-preset-angular/setup-jest';

How to prevent it

  • Keep jest-preset-angular, the setup file, and the transform config in sync with your Angular version.
  • Allow @angular ESM through transformIgnorePatterns.
  • Import the preset setup so zone.js loads.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →