canirequire

canirequire › CommonJS › @testing-library/react-hooks

Is @testing-library/react-hooks ESM-only? Can you require() it?

Simple and complete React hooks testing utilities that encourage good testing practices.

Last verified Sep 9, 2026 against @testing-library/react-hooks@8.0.1. Markdown · JSON

CommonJS CommonJS on paper — require() failed in our runtime test

@testing-library/react-hooks declares a CommonJS entry only, but require("@testing-library/react-hooks") failed on every Node.js version in our probe: Could not auto-detect a React renderer. Are you sure you've installed one of the following. import "@testing-library/react-hooks" resolves to the same file, so it fails the same way. That usually means a missing peer dependency, a browser-only global, or a package that is not meant to be loaded directly; see the runtime table below.

What to do

  1. require("@testing-library/react-hooks") failed in our probe on every Node.js version (Could not auto-detect a React renderer. Are you sure you've installed one of the following); check the package README for peer dependencies or setup before relying on it.
  2. From ES modules use the default import: import reactHooks from "@testing-library/react-hooks"; then destructure. Named imports only work when Node.js can statically detect the exports.
  3. TypeScript: types are bundled; install nothing extra.
Latest
8.0.1 (Jun 18, 2022)
Module format
CommonJS
Last CommonJS version
8.0.1
TypeScript types
Bundled
Node engines
>=12
Weekly downloads
2.4M
License
MIT

Does @testing-library/react-hooks@8.0.1 actually load? Runtime test results

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

Runtimerequire("@testing-library/react-hooks")import "@testing-library/react-hooks"
Node.js 18✗ failsError✗ failsError
Node.js 20✗ failsError✗ failsError
Node.js 22✗ failsError✗ failsError
Node.js 24✗ failsError✗ failsError
Node.js 26✗ failsError✗ failsError
Bun 1.4.0✗ failsError✗ failsError

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/react-hooks

ES modules (import)

import reactHooks from "@testing-library/react-hooks";

Named imports from a CommonJS package only work when Node.js can statically detect them. If a named import fails, use the default import and destructure.

CommonJS (require)

// require("@testing-library/react-hooks") failed in our probe on every Node.js version we test (Could not auto-detect a React renderer. Are you sure you've installed one of the following); see the runtime table.
const reactHooks = require("@testing-library/react-hooks");

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 (37 versions; the newest 37 shown).

VersionsFormatFirst published
1.0.0 – 8.0.1CommonJSJun 19, 2019

Frequently asked

Is @testing-library/react-hooks ESM-only?

@testing-library/react-hooks@8.0.1 declares a CommonJS entry, but require() fails at runtime. @testing-library/react-hooks declares a CommonJS entry only, but require("@testing-library/react-hooks") failed on every Node.js version in our probe: Could not auto-detect a React renderer. Are you sure you've installed one of the following. import "@testing-library/react-hooks" resolves to the same file, so it fails the same way. That usually means a missing peer dependency, a browser-only global, or a package that is not meant to be loaded directly; see the runtime table below.

Can I require @testing-library/react-hooks?

Not in practice. @testing-library/react-hooks declares a CommonJS entry, but require("@testing-library/react-hooks") failed on every Node.js version in our probe: Could not auto-detect a React renderer. Are you sure you've installed one of the following. Check the package README for peer dependencies or setup before relying on it.

Can I import @testing-library/react-hooks with ES module syntax?

Yes. import reactHooks from "@testing-library/react-hooks" works in Node.js and Bun because they support importing CommonJS modules. Named imports work only when Node.js can statically detect the exports.

Does @testing-library/react-hooks work in Bun?

Importing @testing-library/react-hooks failed in Bun 1.4.0 on Sep 9, 2026: error: Could not auto-detect a React renderer. Are you sure you've installed one of the following

Does @testing-library/react-hooks ship TypeScript types?

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

Links

Other commonjs packages

Similar popularity