canirequire › Dual (CommonJS + ESM) › vitest
Is vitest ESM-only? Can you require() it?
Next generation testing framework powered by Vite
Last verified Sep 9, 2026 against vitest@5.0.0. JSON
Dual (CommonJS + ESM) Dual package — both require() and import work
vitest publishes both a CommonJS entry and a native ESM entry (ESM added in 0.0.1). require("vitest") and import "vitest" both work on every supported Node.js version and in Bun.
Does vitest@5.0.0 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("vitest") from a CommonJS file and import "vitest" from an ES module.
| Runtime | require("vitest") | import "vitest" |
|---|---|---|
| Node.js 18 | ✗ failsError: Vitest cannot be imported in a CommonJS module using require(). Please use "import" instead. | ✓ works |
| Node.js 20 | ✗ failsError: Vitest cannot be imported in a CommonJS module using require(). Please use "import" instead. | ✓ works |
| Node.js 22 | ✗ failsError: Vitest cannot be imported in a CommonJS module using require(). Please use "import" instead. | ✓ works |
| Node.js 24 | ✗ failsError: Vitest cannot be imported in a CommonJS module using require(). Please use "import" instead. | ✓ works |
| Node.js 26 | ✗ failsError: Vitest cannot be imported in a CommonJS module using require(). Please use "import" instead. | ✓ works |
| Bun 1.4 | ✗ failserror: Vitest cannot be imported in a CommonJS module using require(). Please use "import" instead. | ✓ works |
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 vitest
ES modules (import)
import vitest from "vitest";CommonJS (require)
const vitest = require("vitest");Module format by version
Derived from the type, main and exports fields of every stable release on npm (410 versions; the newest 60 shown).
| Versions | Format | First published |
|---|---|---|
| 2.1.5 – 5.0.0 | Dual (CommonJS + ESM) | Nov 13, 2024 |
Frequently asked
Is vitest ESM-only?
vitest@5.0.0 ships CommonJS and ESM builds. vitest publishes both a CommonJS entry and a native ESM entry (ESM added in 0.0.1). require("vitest") and import "vitest" both work on every supported Node.js version and in Bun.
Can I require vitest?
Yes. vitest ships a CommonJS entry, so require("vitest") works on every Node.js version, alongside the native ESM entry for import.
Does vitest work in Bun?
Yes. import "vitest" loaded successfully in Bun 1.4 on Sep 9, 2026.
Does vitest ship TypeScript types?
Yes. vitest bundles its own type declarations; no @types package is needed.
Links
Other dual (commonjs + esm) packages
- minimatch 10.2.6Dual
- brace-expansion 5.0.9Dual
- lru-cache 11.5.2Dual
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
- js-yaml 5.4.1Dual
Similar popularity
- word-wrap 1.2.5CommonJS
- log-symbols 7.0.1ESM-only
- express 5.2.1CommonJS
- async 3.2.6CommonJS
- prop-types 15.8.1CommonJS
- forwarded 0.2.0CommonJS
- setprototypeof 1.2.0CommonJS
- object-keys 1.1.1CommonJS