canirequire

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

  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.
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

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.

Runtimerequire("@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).

VersionsFormatFirst published
6.1.0 – 7.0.1Dual (CommonJS + ESM)Aug 23, 2023
5.10.0 – 6.0.1CommonJSJun 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

Similar popularity