# Is @jest/globals ESM-only? Can you require() it?

> @jest/globals@30.5.1 declares a CommonJS entry, but require() fails at runtime. CommonJS on paper — require() failed in our runtime test.

Last verified Sep 9, 2026 against @jest/globals@30.5.1.

@jest/globals declares a CommonJS entry only, but require("@jest/globals") failed on every Node.js version in our probe: Do not import `@jest/globals` outside of the Jest test environment. import "@jest/globals" 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("@jest/globals") failed in our probe on every Node.js version (Do not import `@jest/globals` outside of the Jest test environment); check the package README for peer dependencies or setup before relying on it.
2. From ES modules use the default import: import globals from "@jest/globals"; then destructure. Named imports only work when Node.js can statically detect the exports.
3. TypeScript: types are bundled; install nothing extra.

## Facts

- Latest: 30.5.1 (Sep 1, 2026)
- Module format: CommonJS
- Last CommonJS version: 30.5.1
- TypeScript types: bundled
- Node engines: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0
- Weekly downloads: 35.4M
- License: MIT

## Runtime test results for @jest/globals@30.5.1

Installed and executed on Sep 9, 2026 with require("@jest/globals") from a CommonJS file and import "@jest/globals" from an ES module.

| Runtime | require("@jest/globals") | import "@jest/globals" |
|---|---|---|
| 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 @jest/globals

ES modules:

```js
import globals from "@jest/globals";
```

CommonJS:

```js
// require("@jest/globals") failed in our probe on every Node.js version we test (Do not import `@jest/globals` outside of the Jest test environment); see the runtime table.
const globals = require("@jest/globals");
```

## Module format by version

Derived from the type, main and exports fields of every stable release on npm (85 versions; the newest 60 shown).

| Versions | Format | First published |
|---|---|---|
| 27.2.1 – 30.5.1 | CommonJS | Sep 20, 2021 |

## Frequently asked

**Is @jest/globals ESM-only?**

@jest/globals@30.5.1 declares a CommonJS entry, but require() fails at runtime. @jest/globals declares a CommonJS entry only, but require("@jest/globals") failed on every Node.js version in our probe: Do not import `@jest/globals` outside of the Jest test environment. import "@jest/globals" 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 @jest/globals?**

Not in practice. @jest/globals declares a CommonJS entry, but require("@jest/globals") failed on every Node.js version in our probe: Do not import `@jest/globals` outside of the Jest test environment. Check the package README for peer dependencies or setup before relying on it.

**Can I import @jest/globals with ES module syntax?**

Yes. import globals from "@jest/globals" 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 @jest/globals work in Bun?**

Importing @jest/globals failed in Bun 1.4.0 on Sep 9, 2026: error: Do not import `@jest/globals` outside of the Jest test environment

**Does @jest/globals ship TypeScript types?**

Yes. @jest/globals bundles its own type declarations; no @types package is needed.

## Links

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