## TL;DR

transformIgnorePatterns matches the full file path, so allowlist the package with a negative lookahead like '/node_modules/(?!my-pkg/)'. The default already ignores all of node_modules, so extend the pattern rather than replacing it outright.

## The query

```text
jest transformIgnorePatterns not excluding node_modules package
```

## Use this when

- Jest chokes on an ESM package
- an import-statement error naming a dependency
- adding a new ESM dependency breaks tests

## Not for

- transforming app source
- babel config issues
- ESM in your own code

## Steps

1. Read the import error and confirm it points at a file inside node_modules. Expected output: the stack trace names the package file.
2. Check the package's published files to confirm it ships ESM that Jest cannot parse. Expected output: ESM syntax found in the published package files.
3. Set transformIgnorePatterns to keep the node_modules anchor with a negative lookahead for the package. Expected output: the pattern contains the lookahead naming the package.
4. If the project overrides the default pattern, merge with the default instead of replacing it. Expected output: node_modules still ignored except the allowlisted package.
5. Re-run and confirm the import works and the rest of node_modules stays untransformed. Expected output: a green run with fast transforms.

## Provenance

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