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
- 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.
- 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.
- TypeScript: types are bundled; install nothing extra.
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.
| Runtime | require("@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).
| 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
Other commonjs packages
- debug 4.4.3CommonJS
- semver 7.8.5CommonJS
- ms 2.1.3CommonJS
- picomatch 4.0.7CommonJS
- ajv 8.20.0CommonJS
- source-map 0.8.0CommonJS
- react-is 19.2.8CommonJS
- readable-stream 4.7.0CommonJS
Similar popularity
- web-vitals 6.2.1Dual
- @tootallnate/once 3.0.1ESM-only
- react-transition-group 4.4.5CommonJS
- postcss-nested 8.0.1ESM-only
- @babel/plugin-syntax-nullish-coalescing-operator 7.8.3CommonJS
- dlv 1.1.3CommonJS
- @smithy/middleware-stack 4.5.2CommonJS
- cacache 21.0.1CommonJS