{"id":10431,"library":"vitest","title":"Vitest","description":"Vitest is a next-generation testing framework powered by Vite, offering a fast and integrated testing experience. The current stable version is 4.1.4. It maintains a rapid release cycle, with frequent patch releases addressing bug fixes and minor features, alongside regular minor versions introducing new capabilities and experimental features.","status":"active","version":"4.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/vitest-dev/vitest","tags":["javascript","vite","vitest","test","jest","typescript"],"install":[{"cmd":"npm install vitest","lang":"bash","label":"npm"},{"cmd":"yarn add vitest","lang":"bash","label":"yarn"},{"cmd":"pnpm add vitest","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Vitest primarily uses ESM, aligning with modern Node.js environments.","symbol":"test","correct":"import { test } from 'vitest'"},{"symbol":"expect","correct":"import { expect } from 'vitest'"},{"symbol":"vi","correct":"import { vi } from 'vitest'"}],"quickstart":{"code":"import { test, expect } from 'vitest';\n\nfunction add(a: number, b: number): number {\n  return a + b;\n}\n\ntest('adds two numbers', () => {\n  expect(add(1, 2)).toBe(3);\n});\n\n// To run: npx vitest","lang":"typescript","description":"This example demonstrates a basic Vitest test file, importing `test` and `expect` to define and assert a simple function. It's designed to be runnable by executing `npx vitest` in your project's terminal."},"warnings":[{"fix":"Explicitly configure `setupFiles` paths within your Vitest configuration if they are located outside the current project root, or move them into your project's directory structure.","message":"As of v4.1.2, Vitest no longer resolves `setupFiles` from parent directories. This may break existing configurations where setup files were implicitly picked up from a higher-level directory.","severity":"breaking","affected_versions":">=4.1.2"},{"fix":"Use experimental features with caution and be prepared for potential adjustments in future patch or minor releases. Consult the latest documentation for specific feature stability.","message":"Features explicitly marked as 'Experimental Features' in the changelog or documentation are subject to change, removal, or breaking changes without prior major version bumps.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade your Node.js environment to a supported version. Tools like `nvm` (Node Version Manager) can help you easily manage and switch Node.js versions.","message":"Vitest requires Node.js version `^20.0.0 || ^22.0.0 || >=24.0.0`. Running with older Node.js versions is not supported and may lead to unexpected errors or failures.","severity":"gotcha","affected_versions":">=4.1.0"},{"fix":"Install or upgrade `vite` to a compatible version in your project: `npm install vite@^6.0.0 || vite@^7.0.0 || vite@^8.0.0` or `yarn add vite@^6.0.0 || vite@^7.0.0 || vite@^8.0.0`.","message":"Vitest has `vite` as a peer dependency, requiring version `^6.0.0 || ^7.0.0 || ^8.0.0`. Ensure Vite is installed and compatible with your Vitest version.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-18T00:00:00.000Z","next_check":"2026-07-17T00:00:00.000Z","problems":[{"fix":"Install or upgrade `vite` to a compatible version: `npm install vite@^6.0.0 || vite@^7.0.0 || vite@^8.0.0` or `yarn add vite@^6.0.0 || vite@^7.0.0 || vite@^8.0.0`.","cause":"The `vite` peer dependency is missing or an incompatible version is installed in your project.","error":"Error: Cannot find module 'vite'"},{"fix":"Import `test` and `expect` explicitly: `import { test, expect } from 'vitest';`. If you intend to use globals, ensure `globals: true` is set in your `vitest.config.ts`.","cause":"The global `test` (or `expect`, `describe`, etc.) API is not automatically available, or the test file is not being processed by Vitest.","error":"ReferenceError: test is not defined"},{"fix":"Ensure your project is configured for ESM (e.g., add `\"type\": \"module\"` to your `package.json`), or update Node.js to a supported version (`^20.0.0 || ^22.0.0 || >=24.0.0`).","cause":"You are attempting to use Vitest in a CommonJS context without proper configuration for ESM, or running on an older Node.js version that lacks full ESM support.","error":"ERR_REQUIRE_ESM: require() of ES Module ... not supported."},{"fix":"Run Vitest locally with the update flag (`npx vitest --update` or `npx vitest -u`) to generate and commit the updated snapshots. In CI, ensure snapshots are not updated by setting `update: \"none\"` in config if desired.","cause":"A snapshot test failed because the recorded snapshot does not match the current output. This often happens in CI environments where snapshots are not updated.","error":"SnapshotMismatchError"},{"fix":"Convert your test files and potentially your Vitest configuration to use ESM syntax (`import`/`export`), or configure your project's `package.json` with `\"type\": \"module\"`.","cause":"You are trying to `require()` an ESM-only package or file, which is not allowed in a CommonJS context.","error":"SyntaxError: Must use import to load ES Module:"}],"ecosystem":"npm"}