Vitest Workspace Errors - "Cannot define workspace" in a Monorepo
Vitest workspaces let one command run every package’s tests, but the configuration is easy to get wrong: a workspace defined in two places, a glob that matches nothing, or a per-package config that conflicts with the root.
What this error means
Running Vitest at the monorepo root errors about the workspace - no projects matched the workspace glob, or it complains that workspace and inline projects are both defined. Individual packages test fine in isolation.
Error: Vitest workspace was not able to resolve any projects.
workspace: ['packages/*']
matched: 0 projects
Make sure each project has a vitest/vite config or a "test" field.Common causes
Workspace glob matches no valid projects
The vitest.workspace.ts glob points at directories that have no Vitest/Vite config or test field, so Vitest resolves zero projects and exits.
Workspace defined in conflicting places
Defining both a vitest.workspace.ts file and an inline test.projects in the root config (or two workspace files) makes Vitest ambiguous about which to use.
How to fix it
Define one workspace that matches real projects
// vitest.workspace.ts
export default [
'packages/*', // each must have a vite/vitest config
{ test: { name: 'unit', root: './app' } },
];Verify each project resolves
- Confirm every globbed directory has a
vite.config/vitest.configor atestfield. - Remove duplicate workspace definitions - keep a single source of truth.
- Run
vitest --project <name>to validate one project at a time.
How to prevent it
- Keep exactly one workspace definition for the monorepo.
- Ensure every globbed package ships its own Vitest/Vite config.
- Test the workspace resolution in CI so an empty match is caught.