canirequire

canirequire › ESM-only › 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. Markdown · JSON

ESM-only ESM-only since 1.0.0 — last CommonJS version is 0.34.6

vitest dropped its CommonJS build in 1.0.0 (December 2023). The last version with a plain require()-able CommonJS entry is 0.34.6, published Sep 29, 2023; it declares support for Node.js >=v14.18.0.

require("vitest") fails on every Node.js version we test, even Node.js 22.12+ and newer where require(esm) exists: the CommonJS entry declared by vitest@5.0.0 exists only to throw (Vitest cannot be imported in a CommonJS module using require(). Please use "import" instead). That includes Node.js 18: no Node.js version can load vitest@5.0.0 with a synchronous require().

vitest@5.0.0 declares engines "^22.12.0 || ^24.0.0 || >=26.0.0", so Node.js 18, 20 are outside its supported range regardless of module format.

What to do

  1. require("vitest") fails on every Node.js version we test, even Node.js 22.12+ and newer where require(esm) exists: the CommonJS entry declared by vitest@5.0.0 exists only to throw (Vitest cannot be imported in a CommonJS module using require(). Please use "import" instead).
  2. From a CommonJS file, use a dynamic import inside an async function: const vitest = await import("vitest"). That works on every Node.js version the package supports (^22.12.0 || ^24.0.0 || >=26.0.0).
  3. If you need a synchronous require() or run Node.js 18: npm install vitest@0.34.6, the last CommonJS release (published Sep 29, 2023); it declares Node.js >=v14.18.0.
  4. vitest@5.0.0 declares engines "^22.12.0 || ^24.0.0 || >=26.0.0", so Node.js 18, 20 are unsupported regardless: upgrade Node.js or pin an older release.
  5. TypeScript: types are bundled; install nothing extra.
Latest
5.0.0 (Sep 3, 2026)
Module format
ESM-only
Last CommonJS version
0.34.6
ESM-only since
1.0.0 (Dec 4, 2023)
TypeScript types
Bundled
Node engines
^22.12.0 || ^24.0.0 || >=26.0.0
Weekly downloads
92.7M
License
MIT

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.

Runtimerequire("vitest")import "vitest"
Node.js 18✗ failsError✓ works
Node.js 20✗ failsError✓ works
Node.js 22✗ failsError✓ works
Node.js 24✗ failsError✓ works
Node.js 26✗ failsError✓ works
Bun 1.4.0✗ failsError✓ works

How to import vitest

ES modules (import)

import * as vitest from "vitest";

Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.

CommonJS (require)

// require("vitest") fails on every Node.js version we test: the CommonJS entry only throws (Vitest cannot be imported in a CommonJS module using require(). Please use "import" instead).

// Any Node.js version the package supports (^22.12.0 || ^24.0.0 || >=26.0.0), from an async function:
async function main() {
  const vitest = await import("vitest");
}

// Or pin the last CommonJS release (declares Node.js >=v14.18.0):
// npm install vitest@0.34.6

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 (410 versions; the newest 60 shown).

VersionsFormatFirst published
2.1.5 – 5.0.0ESM-onlyNov 13, 2024

Frequently asked

Is vitest ESM-only?

vitest@5.0.0 is ESM-only. vitest dropped its CommonJS build in 1.0.0 (December 2023). The last version with a plain require()-able CommonJS entry is 0.34.6, published Sep 29, 2023; it declares support for Node.js >=v14.18.0.

Which version of vitest still supports CommonJS / require()?

0.34.6 is the last version of vitest with a CommonJS build; it declares Node.js >=v14.18.0. Install it with "npm install vitest@0.34.6". Every version from 1.0.0 on is ESM-only.

How do I use vitest from a CommonJS file?

From a CommonJS file, use a dynamic import inside an async function: const vitest = await import("vitest"). That works on every Node.js version the package supports (^22.12.0 || ^24.0.0 || >=26.0.0). require("vitest") fails on every Node.js version we test, even Node.js 22.12+ and newer where require(esm) exists: the CommonJS entry declared by vitest@5.0.0 exists only to throw (Vitest cannot be imported in a CommonJS module using require(). Please use "import" instead). Alternatively pin vitest@0.34.6 (declares Node.js >=v14.18.0).

Does vitest work in Bun?

Yes. import "vitest" loaded successfully in Bun 1.4.0 on Sep 9, 2026.

Does vitest ship TypeScript types?

Yes. vitest bundles its own type declarations; no @types package is needed.

Links

Other esm-only packages

Similar popularity