## TL;DR

Jest failed to parse a file, usually an untransformed ESM import or a non-JS asset. Find which file and token the error names, add the transform or moduleNameMapper entry, and re-run.

## Error

```text
Test suite failed to run
    Jest encountered an unexpected token
    /app/node_modules/some-lib/index.js:1
    ({"Object.[anonymous]":function(module,exports,require,__dirname,__filename,jest){import x from 'y';
                                                                                      ^^^^^^
```

## Steps

1. Read the error: it names the file and the token (`import`, `export`, `<` for JSX/SVG). Expected: you know what failed to parse.
2. If it is ESM in node_modules, add it to `transformIgnorePatterns` exceptions: `transformIgnorePatterns: ['node_modules/(?!(some-lib)/)']`. Expected: Jest transforms that package.
3. If it is an asset (svg, css, image), map it: `moduleNameMapper: { '[.](svg|css)$': '[rootDir]/test/__mocks__/fileMock.js' }`. Expected: imports resolve to a stub.
4. If it is your own ESM source, ensure babel-jest or ts-jest is configured for it. Expected: your code transforms.
5. Re-run the single suite. Expected: the suite runs instead of failing to parse.

## When to use

- `Test suite failed to run` with `unexpected token`.
- After adding a new dependency or asset import.

## When not to use

- Tests run but fail (assertion or logic failures).
- TypeScript type errors (tsc, not Jest transform).

## Tool compatibility

- Jest 27 through 30; babel-jest, ts-jest.

## Variant phrasings

### Jest encountered an unexpected token import

The ESM variant; fix with transformIgnorePatterns.

### Jest unexpected token export

Same fix from the export side.

## Why it happens

Jest transforms files with babel by default but skips node_modules. Any ESM or non-JS syntax outside the transform pipeline crashes the parser.

## Edge cases

- `transformIgnorePatterns` is a denylist; the regex exception syntax is easy to get backwards.
- Dual CJS/ESM packages need the right `main`/`module` resolution; check the package's exports.
- Vitest handles ESM natively; migrating avoids this whole class of error.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_cNkoLABm3803XTlm07II2g
