Vitest "ReferenceError: describe is not defined" (globals) in CI
Unlike Jest, Vitest does not inject describe, it, and expect as globals by default. Either import them from vitest in each test, or set globals: true in the config so they are available everywhere.
What this error means
Tests fail with "ReferenceError: describe is not defined" or "expect is not defined", often only in CI where a local IDE config masked the difference.
ReferenceError: describe is not defined
❯ src/sum.test.ts:1:1
1| describe('sum', () => {
| ^Common causes
globals is not enabled and APIs are not imported
Vitest keeps test APIs off the global scope by default, so a Jest-style test that never imports them fails.
The globals TypeScript types were assumed
The code relied on vitest/globals types being present without actually turning on globals: true at runtime.
How to fix it
Enable globals in the config
- Set
globals: trueundertestin the config. - Add
vitest/globalstotypesin tsconfig for editor support. - Re-run so the APIs are injected globally.
export default defineConfig({
test: { globals: true },
})Or import the APIs explicitly
Keep globals off and import what each file uses; this is the most portable option.
import { describe, it, expect } from 'vitest'How to prevent it
- Decide once: globals on, or import in every test.
- Add
vitest/globalsto tsconfig types when using globals. - Do not assume Jest-style globals carry over to Vitest.