## TL;DR

Jest runs in CommonJS by default, so `import` in your test files fails without a transform. Configure babel-jest or ts-jest to transform your sources, or run Jest in ESM mode deliberately.

## Error

```text
SyntaxError: Cannot use import statement outside a module
    at Runtime.createScriptFromCode
```

## Steps

1. Check for a babel config that handles ESM-to-CJS. Expected: `@babel/preset-env` present, or the error explains its absence.
2. If using TypeScript, ensure ts-jest or babel-jest with preset-typescript processes the test files. Expected: `.ts` tests transform.
3. Verify `transform` in jest config covers your file extensions. Expected: no gaps for `.ts`, `.tsx`, `.jsx`.
4. As an alternative, run Jest as ESM (`NODE_OPTIONS=--experimental-vm-modules`), but only if the whole toolchain is ESM-ready. Expected: a deliberate choice, not an accident.
5. Re-run. Expected: imports work.

## When to use

- The error names your own test or source file.
- A fresh Jest setup or a TS migration.

## When not to use

- The error names a file in node_modules (transformIgnorePatterns skill).
- You are on Vitest (native ESM; different setup).

## Tool compatibility

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

## Variant phrasings

### Jest SyntaxError import statement

The short form; transform configuration is the fix.

### Cannot use import statement in Jest with TypeScript

ts-jest or babel typescript preset missing.

## Why it happens

Node-style ESM `import` is not valid CommonJS. Jest's default runtime is CJS, so something must compile the syntax away.

## Edge cases

- Mixed CJS/ESM codebases need per-file transform decisions; keep the config explicit.
- `jest.mock()` hoisting interacts with ESM transforms; keep mocks at the top.
- ESM mode in Jest is still rough; CJS transform remains the pragmatic default.

## Provenance

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