canirequire › Dual (CommonJS + ESM) › @testing-library/jest-dom
Is @testing-library/jest-dom ESM-only? Can you require() it?
Custom jest matchers to test the state of the DOM
Last verified Sep 9, 2026 against @testing-library/jest-dom@7.0.1. JSON
Dual (CommonJS + ESM) Dual package — both require() and import work
@testing-library/jest-dom publishes both a CommonJS entry and a native ESM entry (ESM added in 6.1.0). require("@testing-library/jest-dom") and import "@testing-library/jest-dom" both work on every supported Node.js version and in Bun.
Does @testing-library/jest-dom@7.0.1 actually load? Runtime test results
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 | ✗ failsReferenceError | ✗ failsReferenceError |
| Node.js 20 | ✗ failsReferenceError | ✗ failsReferenceError |
| Node.js 22 | ✗ failsReferenceError | ✗ failsReferenceError |
| Node.js 24 | ✗ failsReferenceError | ✗ failsReferenceError |
| Node.js 26 | ✗ failsReferenceError | ✗ failsReferenceError |
| Bun 1.4 | ✗ failsReferenceError | ✗ failsReferenceError |
A failing require() on a CommonJS package usually means the package needs a browser/DOM global, a peer dependency, or a native binary that is not available in a bare Node.js process.
How to import @testing-library/jest-dom
ES modules (import)
import jestDom from "@testing-library/jest-dom";CommonJS (require)
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 ships CommonJS and ESM builds. @testing-library/jest-dom publishes both a CommonJS entry and a native ESM entry (ESM added in 6.1.0). require("@testing-library/jest-dom") and import "@testing-library/jest-dom" both work on every supported Node.js version and in Bun.
Can I require @testing-library/jest-dom?
Yes. @testing-library/jest-dom ships a CommonJS entry, so require("@testing-library/jest-dom") works on every Node.js version, alongside the native ESM entry for import.
Does @testing-library/jest-dom work in Bun?
Importing @testing-library/jest-dom failed in Bun 1.4 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
Other dual (commonjs + esm) packages
- minimatch 10.2.6Dual
- brace-expansion 5.0.9Dual
- lru-cache 11.5.2Dual
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
- js-yaml 5.4.1Dual
Similar popularity
- is-weakmap 2.0.2CommonJS
- boolbase 2.0.0ESM-only
- unist-util-stringify-position 4.0.0ESM-only
- jest-haste-map 30.5.1Dual
- @radix-ui/react-visually-hidden 1.2.11Dual
- istanbul-lib-source-maps 5.0.6CommonJS
- webpack-sources 3.5.1CommonJS
- @tanstack/react-query 5.102.8Dual