# Is vitest ESM-only? Can you require() it?

> vitest@5.0.0 is ESM-only. ESM-only since 1.0.0 — last CommonJS version is 0.34.6.

Next generation testing framework powered by Vite

Last verified Sep 9, 2026 against vitest@5.0.0.

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.

## Facts

- 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

## Runtime test results for vitest@5.0.0

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 | fails (Error) | works |
| Node.js 20 | fails (Error) | works |
| Node.js 22 | fails (Error) | works |
| Node.js 24 | fails (Error) | works |
| Node.js 26 | fails (Error) | works |
| Bun 1.4.0 | fails (Error) | works |

## How to import vitest

ES modules:

```js
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:

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

| Versions | Format | First published |
|---|---|---|
| 2.1.5 – 5.0.0 | ESM-only | Nov 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

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