Skip to content
Latchkey

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.

Vitest
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.ts

Common 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

  1. Read the stack trace to find which module failed to load.
  2. Add it to devDependencies and re-run npm ci.
  3. Guard any env vars the config reads so a missing value does not throw.
Terminal
npm install -D vite-tsconfig-paths
npm ci

Keep the config ESM-consistent

Use defineConfig and ESM imports, and make sure package.json type matches the config extension so Node loads it correctly.

vitest.config.ts
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.

Frequently asked questions

What causes ""Failed to load url ... vitest.config.ts""?
The config imports a plugin (for example vite-tsconfig-paths) that is a devDependency missing from the CI install, so the import throws.
How do I fix "Failed to load url ... vitest.config.ts"?
Install every dependency the config imports

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card