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. Markdown · JSON
Dual (CommonJS + ESM) Dual package on paper — require() failed in our runtime test
@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
- 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.
- TypeScript: types are bundled; install nothing extra.
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.0 | ✗ 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 * 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 (require)
// 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, corrected where a runtime test of that version contradicted them (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
Other dual (commonjs + esm) packages
- minimatch 10.2.6Dual
- brace-expansion 5.0.9Dual
- lru-cache 11.5.2Dual
- tslib 2.8.1Dual
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
Similar popularity
- boolbase 2.0.0ESM-only
- unist-util-stringify-position 4.0.0ESM-only
- @radix-ui/react-focus-scope 1.1.16Dual
- jest-haste-map 30.5.1Dual
- @babel/plugin-transform-react-jsx-source 7.29.7CommonJS
- @radix-ui/react-visually-hidden 1.2.11Dual
- istanbul-lib-source-maps 5.0.6CommonJS
- webpack-sources 3.5.1CommonJS