high

SyntaxError: Unexpected token

Jest encountered syntax it cannot parse. This usually means a file needs to be transformed (e.g., TypeScript, JSX, ESM) but the transformer is not configured.

Common Causes

  1. 1TypeScript file imported without ts-jest or @swc/jest configured
  2. 2JSX used without the appropriate transformer
  3. 3ES module syntax (import/export) in a CommonJS environment
  4. 4CSS or asset imports not mocked
  5. 5Node module using ESM that needs transforming

How to Fix

Configure the transform for TypeScript

// jest.config.ts
export default {
  transform: {
    '^.+\\.tsx?$': ['ts-jest', {
      tsconfig: 'tsconfig.json',
    }],
  },
};

Use ts-jest to transform TypeScript and TSX files. Alternatively, use @swc/jest for faster transforms.

Transform ESM modules

// jest.config.ts
export default {
  transformIgnorePatterns: [
    'node_modules/(?!(esm-package|another-esm-package)/)',
  ],
};

By default, Jest ignores node_modules. Override this for ESM packages that need transformation.

How ObserveOne Helps

ObserveOne detects test configuration issues and suggests optimal transform setups for your stack.

Start Monitoring Free

Related Errors