vitest-dev/vitest · error · Error
Cannot define a nested project for a ${browser} browser. The
Error message
Cannot define a nested project for a ${browser} browser. The project name "${name}" was already defined. If you have multiple instances for the same browser, make sure to define a custom "name". All projects should have unique names. Make sure your configuration is correct. What it means
During browser-instance expansion (resolveProjects.ts:749-757), each instance becomes its own project and its name is added to a `names` set. If two instances produce the same name (e.g. two chromium instances without custom names), the second throws. The message tells you to give each instance a custom `name` when running multiple instances of the same browser engine.
Source
Thrown at packages/vitest/src/node/projects/resolveProjects.ts:750
`@vitest/coverage-v8 does not work with\n${browserConfig}\n`
+ `\nUse either:\n${correctExample}`
+ `\n\n...or change your coverage provider to:\n${coverageExample}\n`,
)
}
if (globalConfig.inspect || globalConfig.inspectBrk) {
const inspectOption = `--inspect${globalConfig.inspectBrk ? '-brk' : ''}`
throw new Error(
`${inspectOption} does not work with\n${browserConfig}\n`
+ `\nUse either:\n${correctExample}`
+ `\n\n...or disable ${inspectOption}\n`,
)
}
}
if (names.has(name)) {
throw new Error(
[
`Cannot define a nested project for a ${browser} browser. The project name "${name}" was already defined. `,
'If you have multiple instances for the same browser, make sure to define a custom "name". ',
'All projects should have unique names. Make sure your configuration is correct.',
].join(''),
)
}
names.add(name)
const clonedConfig = cloneProjectConfigForBrowserInstance(projectConfig, instance)
clonedConfig.name = name
result.push({
viteConfig, // shared with parent
projectConfig: clonedConfig,
ancestors: entry.ancestors,
})
})View on GitHub (pinned to d568f8ce37)
Solutions
- Give every instance a unique `name`: { browser: 'chromium', name: 'chromium-mobile' }, { browser: 'chromium', name: 'chromium-desktop' }.
- If you only need one instance per engine, remove the duplicate.
- Generate names programmatically from the options (e.g. viewport) when building the instances array.
Example fix
// before
test: { browser: { enabled: true, provider: 'playwright', instances: [
{ browser: 'chromium', viewport: { width: 375, height: 667 } },
{ browser: 'chromium', viewport: { width: 1280, height: 720 } },
] } }
// after
test: { browser: { enabled: true, provider: 'playwright', instances: [
{ browser: 'chromium', name: 'mobile', viewport: { width: 375, height: 667 } },
{ browser: 'chromium', name: 'desktop', viewport: { width: 1280, height: 720 } },
] } } Defensive patterns
Strategy: validation
Validate before calling
const instanceNames = instances.map(i => i.name ?? i.browser)
const dupes = instanceNames.filter((n, i) => instanceNames.indexOf(n) !== i)
if (dupes.length) throw new Error(`Duplicate browser instance names: ${[...new Set(dupes)].join(', ')}`) Type guard
function uniqueInstanceNames(instances: { name?: string; browser: string }[]): boolean {
const names = instances.map(i => i.name ?? i.browser)
return new Set(names).size === names.length
} Prevention
- Give every instance an explicit `name`, especially when repeating an engine.
- Derive names from distinguishing options (viewport, locale) when generating instances.
- Run one instance per engine unless you really need multiples.
When it happens
Trigger: browser.instances contains two entries with the same browser engine and no distinguishing `name` (both fall back to the engine name); instances with explicitly identical `name` fields.
Common situations: Wanting to run chromium twice with different viewports/options but forgetting to name them; copy-pasting an instance; defaulting instances from an array of options that omits name.
Related errors
- Project name "${name}" is not unique. All projects should ha
- Project name "${name}"${entryFile ? ` from "${entryFile}"` :
- The browser configuration must have a "browser" property. Th
- The browser configuration must have a "name" property. This
- The instance cannot have a different provider from its paren
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/31c54bfbaace443e.json.
Report an issue: GitHub.