canirequire

canirequireDual (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.

Latest
5.0.0 (Sep 3, 2026)
Module format
Dual (CommonJS + ESM)
Last CommonJS version
5.0.0
Native ESM since
0.0.1
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: 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).

VersionsFormatFirst published
2.1.5 – 5.0.0Dual (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

Similar popularity