-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Describe the bug
When using instances: [{ browser: 'chromium' }] with Vitest 3 + @storybook/addon-vitest, the following error occurs in certain project environments:
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Startup Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: Cannot define a nested project for a chromium browser. The project name "storybook (chromium)" 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.
at file:///my-org/my-repo/node_modules/vitest/dist/chunks/cli-api.BkDphVBG.js:7550:31
at Array.forEach (<anonymous>)
at file:///my-org/my-repo/node_modules/vitest/dist/chunks/cli-api.BkDphVBG.js:7541:21
at Array.forEach (<anonymous>)
at resolveBrowserProjects (file:///my-org/my-repo/node_modules/vitest/dist/chunks/cli-api.BkDphVBG.js:7512:19)
at resolveProjects (file:///my-org/my-repo/node_modules/vitest/dist/chunks/cli-api.BkDphVBG.js:7508:9)
at async Vitest._setServer (file:///my-org/my-repo/node_modules/vitest/dist/chunks/cli-api.BkDphVBG.js:9319:20)
at async handler (file:///my-org/my-repo/node_modules/vitest/dist/chunks/cli-api.BkDphVBG.js:10169:6)
at async _createServer (file:///my-org/my-repo/node_modules/vite/dist/node/chunks/dep-Cyk9bIUq.js:63069:20)
at async createViteServer (file:///my-org/my-repo/node_modules/vitest/dist/chunks/cli-api.BkDphVBG.js:6911:17)
However, the same configuration works perfectly in a fresh reproduction environment.
Reproduction link
https://github.com/MH4GF/storybook-vitest-reproduction
Reproduction steps
No response
System
Storybook Environment Info:
System:
OS: macOS 14.6
CPU: (8) arm64 Apple M2
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.14.0 - ~/.local/share/mise/installs/node/22.14.0/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 10.9.2 - ~/.local/share/mise/installs/node/22.14.0/bin/npm <----- active
pnpm: 10.14.0 - /opt/homebrew/bin/pnpm
Browsers:
Chrome: 139.0.7258.157
Safari: 17.6
Additional context
Current workaround:
Using the deprecated name: 'chromium'
instead of instances: [{ browser: 'chromium' }]
works but I want to use instances because of problems with vitest-dev/vitest#7981 (reply in thread).
Investigated factors:
- ✅ Package versions: Identical between failing and working environments
- ✅ Vitest configuration: Same configuration works in reproduction
- ✅ Story files: Removing all stories doesn't resolve the issue
- ✅ Storybook configuration: Configuration changes don't affect the error
Configuration that fails:
// vitest.config.mts
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import tsconfigPaths from 'vite-tsconfig-paths';
import { defineConfig } from 'vitest/config';
import { storybookTest } from '@storybook/addon-vitest/vitest-plugin';
export default defineConfig({
plugins: [tsconfigPaths(), react()],
resolve: {
alias: {
'@': resolve(__dirname, './'),
},
},
optimizeDeps: {
include: ['@storybook/addon-vitest', '@storybook/nextjs-vite'],
exclude: ['markdown-to-jsx'],
},
test: {
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
exclude: [
'**/node_modules/**',
'**/dist/**',
'**/.storybook/**',
'**/coverage/**',
'**/*.stories.{ts,tsx}',
'**/*.test.{ts,tsx}',
'**/*.spec.{ts,tsx}',
],
},
projects: [
// Regular unit tests
{
plugins: [tsconfigPaths(), react()],
test: {
name: 'unit',
globals: true,
environment: 'jsdom',
setupFiles: ['./vitest.setup.mts'],
include: ['**/*.{test,spec}.{ts,tsx}'],
exclude: ['**/*.stories.{ts,tsx}', '**/node_modules/**', '**/mock-assets/**'],
typecheck: {
enabled: true,
},
},
},
// Storybook tests
{
plugins: [
tsconfigPaths(),
react(),
storybookTest({
configDir: resolve(__dirname, '.storybook'),
}),
],
define: {
global: 'globalThis',
},
test: {
name: 'storybook',
browser: {
enabled: true,
provider: 'playwright',
headless: true,
// name: 'chromium',
instances: [{ browser: 'chromium' }],
},
testTimeout: 60000,
setupFiles: ['./.storybook/vitest.setup.ts'],
exclude: ['**/node_modules/**'],
},
},
],
},
});
Questions for the community:
- What debugging steps can help identify project-specific factors causing this issue?
- How can I inspect the internal project names that storybookTest plugin creates?
- Are there known project environment factors that could cause different behavior with the same configuration?
The reproduction repository demonstrates that the configuration itself is correct, but something in the original project environment causes the conflict. Any guidance on debugging this project-specific issue would be greatly appreciated.