# Is @testing-library/jest-dom ESM-only? Can you require() it?

> @testing-library/jest-dom@7.0.1 declares CommonJS and ESM builds, but require() fails at runtime. Dual package on paper — require() failed in our runtime test.

Custom jest matchers to test the state of the DOM

Last verified Sep 9, 2026 against @testing-library/jest-dom@7.0.1.

@testing-library/jest-dom declares both a CommonJS entry and a native ESM entry (ESM added in 6.1.0), but require("@testing-library/jest-dom") failed on every Node.js version in our probe: ReferenceError: expect is not defined. That usually means a missing peer dependency, a browser-only global, or a package that refuses to be loaded with require(); see the runtime table below.

## What to do

1. require("@testing-library/jest-dom") failed in our probe on every Node.js version (ReferenceError: expect is not defined); check the package README for peer dependencies or setup before relying on it.
2. TypeScript: types are bundled; install nothing extra.

## Facts

- Latest: 7.0.1 (Aug 9, 2026)
- Module format: Dual (CommonJS + ESM)
- Last CommonJS version: 7.0.1
- Native ESM since: 6.1.0
- TypeScript types: bundled
- Node engines: >=22
- Weekly downloads: 56.0M
- License: MIT

## Runtime test results for @testing-library/jest-dom@7.0.1

Installed and executed on Sep 9, 2026 with require("@testing-library/jest-dom") from a CommonJS file and import "@testing-library/jest-dom" from an ES module.

| Runtime | require("@testing-library/jest-dom") | import "@testing-library/jest-dom" |
|---|---|---|
| Node.js 18 | fails (ReferenceError) | fails (ReferenceError) |
| Node.js 20 | fails (ReferenceError) | fails (ReferenceError) |
| Node.js 22 | fails (ReferenceError) | fails (ReferenceError) |
| Node.js 24 | fails (ReferenceError) | fails (ReferenceError) |
| Node.js 26 | fails (ReferenceError) | fails (ReferenceError) |
| Bun 1.4.0 | fails (ReferenceError) | fails (ReferenceError) |

## How to import @testing-library/jest-dom

ES modules:

```js
import * as jestDom from "@testing-library/jest-dom";
```

Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.

CommonJS:

```js
// require("@testing-library/jest-dom") failed in our probe on every Node.js version we test (ReferenceError: expect is not defined); see the runtime table.
const jestDom = require("@testing-library/jest-dom");
```

## Module format by version

Derived from the type, main and exports fields of every stable release on npm (84 versions; the newest 60 shown).

| Versions | Format | First published |
|---|---|---|
| 6.1.0 – 7.0.1 | Dual (CommonJS + ESM) | Aug 23, 2023 |
| 5.10.0 – 6.0.1 | CommonJS | Jun 11, 2020 |

## Frequently asked

**Is @testing-library/jest-dom ESM-only?**

@testing-library/jest-dom@7.0.1 declares CommonJS and ESM builds, but require() fails at runtime. @testing-library/jest-dom declares both a CommonJS entry and a native ESM entry (ESM added in 6.1.0), but require("@testing-library/jest-dom") failed on every Node.js version in our probe: ReferenceError: expect is not defined. That usually means a missing peer dependency, a browser-only global, or a package that refuses to be loaded with require(); see the runtime table below.

**Can I require @testing-library/jest-dom?**

Not in practice. @testing-library/jest-dom declares a CommonJS entry, but require("@testing-library/jest-dom") failed on every Node.js version in our probe: ReferenceError: expect is not defined. Check the package README for peer dependencies or setup before relying on it.

**Does @testing-library/jest-dom work in Bun?**

Importing @testing-library/jest-dom failed in Bun 1.4.0 on Sep 9, 2026: ReferenceError: expect is not defined

**Does @testing-library/jest-dom ship TypeScript types?**

Yes. @testing-library/jest-dom bundles its own type declarations; no @types package is needed.

## Links

- [@testing-library/jest-dom on npm](https://www.npmjs.com/package/@testing-library/jest-dom)
- [Source repository](https://github.com/testing-library/jest-dom)
- [HTML version](https://canirequire.com/package/@testing-library/jest-dom/)
- [JSON version](https://canirequire.com/package/@testing-library/jest-dom.json)

---

For scripts and AI agents: any package is at https://canirequire.com/package/<name>/index.md (Markdown) or https://canirequire.com/package/<name>.json (JSON); the site index is https://canirequire.com/llms.txt. Fetch the URL directly; no search needed.
