Vitest "Failed to load ... vitest.config.ts" in CI
Vitest imports and evaluates your config file before running anything. If that evaluation throws, you get "failed to load config". The captured stack trace under the message names the real cause: a missing import, an undefined plugin, or a syntax error.
What this error means
Vitest aborts at startup with "failed to load config from /path/vitest.config.ts" followed by a stack trace, before any test file runs.
failed to load config from /home/runner/work/app/app/vitest.config.ts
Error: Cannot find package 'vite-tsconfig-paths' imported from
/home/runner/work/app/app/vitest.config.tsCommon causes
A config dependency is not installed in CI
The config imports a plugin (for example vite-tsconfig-paths) that is a devDependency missing from the CI install, so the import throws.
A runtime error in the config module
The config reads an undefined env var, calls a function that throws, or has a syntax error, which surfaces only when Vitest evaluates it.
How to fix it
Install every dependency the config imports
- Read the stack trace to find which module failed to load.
- Add it to devDependencies and re-run
npm ci. - Guard any env vars the config reads so a missing value does not throw.
npm install -D vite-tsconfig-paths
npm ciKeep the config ESM-consistent
Use defineConfig and ESM imports, and make sure package.json type matches the config extension so Node loads it correctly.
import { defineConfig } from 'vitest/config'
export default defineConfig({ test: { globals: true } })How to prevent it
- List all config plugins in devDependencies.
- Avoid reading required env vars at config load time.
- Keep
type: "module"and config extension consistent.