canirequire

canirequire › CommonJS › @jest/globals

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

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

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

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

Does @jest/globals@30.5.1 actually load? Runtime test results

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

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

ES modules (import)

import globals from "@jest/globals";

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("@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, corrected where a runtime test of that version contradicted them (85 versions; the newest 60 shown).

VersionsFormatFirst published
27.2.1 – 30.5.1CommonJSSep 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

Other commonjs packages

Similar popularity