# @jest/source-map

> Applies source maps to stack traces, so a failing test points at the code you wrote rather than at the code Jest ran.

Latest version **30.5.0** (published 2026-08-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jest/source-map
pnpm add @jest/source-map
yarn add @jest/source-map
bun add @jest/source-map
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; popular repo.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 30.5.0 |
| Published | 2026-08-28 |
| First published | 2019-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^18.14.0 \|\| ^20.0.0 \|\| ^22.0.0 \|\| >=24.0.0 |
| Dependencies | 4 |
| Unpacked size | 34.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 45457 |
| Maintainers | aaronabramov, simenb, rickhanlonii, openjs-operations, cpojer |

## Links

- npm: https://www.npmjs.com/package/@jest/source-map
- Repository: https://github.com/jestjs/jest
- Homepage: https://github.com/jestjs/jest#readme
- Issues: https://github.com/jestjs/jest/issues
- npm.io page: https://npm.io/package/@jest/source-map

## Dependencies (4)

- [callsites](https://npm.io/package/callsites.md) ^3.1.0
- [graceful-fs](https://npm.io/package/graceful-fs.md) ^4.2.11
- [convert-source-map](https://npm.io/package/convert-source-map.md) ^2.0.0
- [@jridgewell/trace-mapping](https://npm.io/package/@jridgewell/trace-mapping.md) ^0.3.31

## Recent versions

- 30.5.0 (latest) — 2026-08-28
- 30.0.0-rc.1 (next) — 2025-06-09
- 30.0.1 — 2025-06-18
- 30.0.0 — 2025-06-10
- 30.0.0-beta.8 — 2025-06-04
- 30.0.0-beta.7 — 2025-06-04
- 30.0.0-beta.6 — 2025-06-03
- 30.0.0-beta.3 — 2025-05-27
- 30.0.0-beta.1 — 2025-05-27
- 30.0.0-alpha.7 — 2025-01-30
- 30.0.0-alpha.6 — 2024-08-08
- 30.0.0-alpha.5 — 2024-05-30
- 30.0.0-alpha.4 — 2024-05-12
- 30.0.0-alpha.3 — 2024-02-20
- 30.0.0-alpha.2 — 2023-11-16
- … 49 more at https://npm.io/package/@jest/source-map/versions

## README

# @jest/source-map

Applies source maps to stack traces, so a failing test points at the code you wrote rather than at the code Jest ran.

This is a module used internally by Jest. It exists because `--enable-source-maps` and `module.setSourceMapsSupport()` do not cover code compiled through `vm`, which is how Jest evaluates test files, and because Node offers no way to register a map for a filename — Jest serves maps from its own transform pipeline rather than from `sourceMappingURL` comments on disk.

## Install

```sh
$ npm install --save @jest/source-map
```

## API

### `SourceMapSupport#install(sourceMaps?: SourceMapRegistry | null, options?: SourceMapSupportInstallOptions): void`

Replaces `Error.prepareStackTrace` in the current realm, so reading `.stack` on any error renders frames against the original sources. `jest-runner` holds one instance per worker and installs once per test file.

`sourceMaps` maps a transformed file to the `.map` file Jest wrote into its transform cache — inside Jest, `runtime.getSourceMaps()`. The `sources` inside a map resolve with URL semantics against the transformed file, not against the map's own location. Files missing from the registry fall back to a `sourceMappingURL` comment on the file itself, which covers pre-compiled output that ships its own map.

```javascript
import {SourceMapSupport} from '@jest/source-map';

const sourceMapSupport = new SourceMapSupport();
sourceMapSupport.install(new Map([['/build/app.js', '/cache/app.js.map']]));

new Error('boom').stack;
// Error: boom
//     at greet (/src/app.ts:12:9)
```

The formatter stays installed for the lifetime of the process, and each call swaps in a new registry. Nothing is restored, deliberately: an error thrown after a test finishes — a stray timer, a floating promise — is the one users have the hardest time placing, and it would otherwise report a position in the transformed file.

A map that cannot be parsed is reported once via `console.warn`; pass `{suppressWarnings: true}` to turn that off.

### `SourceMapSupport#getCallsite(level: number, sourceMaps?: SourceMapRegistry | null): CallSite`

Returns a single remapped [`CallSite`](https://v8.dev/docs/stack-trace-api#customizing-stack-traces), `level` frames above the caller. Used for `--testLocationInResults`. Shares its parsed maps with the installed formatter, so each `.map` file is read once.

### `getCallsite(level: number, sourceMaps?: SourceMapRegistry | null): CallSite`

Deprecated free-function alias of `SourceMapSupport#getCallsite`.

### `SourceMapRegistry`

`Map<string, string>` — transformed file path to source map path.

## Function names are chosen for readability, not for the spec

A frame is named after the source map's `name` at the frame's **own** position. That name is the identifier being _called_ there rather than the enclosing function, so every frame gets annotated with the call on its line:

```
at Object.toBeTruthy (assertionCount.test.js:12:17)
at Object.setTimeout (inside.js:9:3)
```

The spec-correct reading takes the name from the _caller's_ position instead. It is what [`source-map-support@0.5.14`](https://github.com/evanw/node-source-map-support/pull/253) switched to, and it collapses the frames above to `Object.<anonymous>`, because V8 has no name of its own for a module-level frame. Positions are identical either way — only names differ, and only where V8 could not name the frame.

This package optimises for reading a test failure, so it keeps the annotation. If you need the spec semantics, `getCallsite` hands back a `CallSite` you can map yourself.

---
_Source: https://npm.io/package/@jest/source-map · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
