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

> @testing-library/react-hooks@8.0.1 declares a CommonJS entry, but require() fails at runtime. CommonJS on paper — require() failed in our runtime test.

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.

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

## Facts

- 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

## Runtime test results for @testing-library/react-hooks@8.0.1

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.

| Runtime | require("@testing-library/react-hooks") | import "@testing-library/react-hooks" |
|---|---|---|
| Node.js 18 | fails (Error) | fails (Error) |
| Node.js 20 | fails (Error) | fails (Error) |
| Node.js 22 | fails (Error) | fails (Error) |
| Node.js 24 | fails (Error) | fails (Error) |
| Node.js 26 | fails (Error) | fails (Error) |
| Bun 1.4.0 | fails (Error) | fails (Error) |

## How to import @testing-library/react-hooks

ES modules:

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

CommonJS:

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

| Versions | Format | First published |
|---|---|---|
| 1.0.0 – 8.0.1 | CommonJS | Jun 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

- [@testing-library/react-hooks on npm](https://www.npmjs.com/package/@testing-library/react-hooks)
- [Source repository](https://github.com/testing-library/react-hooks-testing-library)
- [HTML version](https://canirequire.com/package/@testing-library/react-hooks/)
- [JSON version](https://canirequire.com/package/@testing-library/react-hooks.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.
