Skip to content

[Bug]: Type 'PreviewAddon<AddonTypes>' is not assignable to type 'PluginOption'.ts(2769), when initializing storybook vitest addon #32895

@ehoodgoren

Description

@ehoodgoren

Describe the bug

I used the vitest.config.ts example config from the docs' page "Vitest addon":

import { defineConfig, defineProject, mergeConfig } from 'vitest/config';

import { storybookTest } from '@storybook/addon-vitest/vitest-plugin';

import path from 'node:path';
import { fileURLToPath } from 'node:url';

const dirname = path.dirname(fileURLToPath(import.meta.url));

import viteConfig from './vite.config';

export default mergeConfig(
  viteConfig,
  defineConfig({
    test: {
      // Use `workspace` field in Vitest < 3.2
      projects: [
        defineProject({
          extends: true,
          plugins: [
            storybookTest({
              // The location of your Storybook config, main.js|ts
              configDir: path.join(dirname, '.storybook'),
              // This should match your package.json script to run Storybook
              // The --no-open flag will skip the automatic opening of a browser
              storybookScript: 'yarn storybook --no-open',
            }),
          ],
          test: {
            name: 'storybook',
            // Enable browser mode
            browser: {
              enabled: true,
              // Make sure to install Playwright
              provider: 'playwright',
              headless: true,
              instances: [{ browser: 'chromium' }],
            },
            setupFiles: ['./.storybook/vitest.setup.ts'],
          },
        }),
      ],
    },
  }),
);

The first error is what's already raised in #32127 - the import is wrong, there's no named export storybookTest. Fixing the import as the IDE suggests to the default import fixes that issue.
We then move to the main point of this issue - the storybookTest part has an error:
Type 'PreviewAddon<AddonTypes>' is not assignable to type 'PluginOption'.ts(2769)
Image

My vitest.setup.ts is exactly as initialized with the npx storybook add @storybook/addon-vitest command:

import * as a11yAddonAnnotations from "@storybook/addon-a11y/preview";
import { setProjectAnnotations } from '@storybook/react-vite';
import * as projectAnnotations from './preview';

// This is an important step to apply the right configuration when testing your stories.
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
setProjectAnnotations([a11yAddonAnnotations, projectAnnotations]);

By the way, the reason I had to make manual changes to vitest.config.ts is that part failed when I ran the
npx storybook add @storybook/addon-vitest command.

I was able to reproduce both issues exactly as they happen in my local env in the attached stackblitz. I updated some versions to match what I have locally, which is basically storyboook 9.x.x latest, vitest 3.x.x latest.
I use npm.

Looking forward to adopt the new vitest addon in my team's storybook!

Reproduction link

https://stackblitz.com/edit/github-nfsbyspe?file=vitest.config.ts

Reproduction steps

Go to the file vitest.config.ts. See the error on storybookTest.

System

Storybook Environment Info:

  System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Pro
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.6.2 - ~/.nvm/versions/node/v21.6.2/bin/node
    Yarn: 1.22.22 - ~/sentra/sentra-app/node_modules/.bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v21.6.2/bin/npm <----- active
  Browsers:
    Safari: 17.6
  npmPackages:
    @storybook/addon-a11y: ^9.1.15 => 9.1.15 
    @storybook/addon-docs: ^9.1.15 => 9.1.15 
    @storybook/addon-links: ^9.1.15 => 9.1.15 
    @storybook/addon-vitest: ^9.1.16 => 9.1.16 
    @storybook/react-vite: ^9.1.15 => 9.1.15 
    chromatic: ^9.1.0 => 9.1.0 
    eslint-plugin-storybook: ^9.1.15 => 9.1.15 
    msw-storybook-addon: ^2.0.6 => 2.0.6 
    storybook: ^9.1.15 => 9.1.15

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Needs Discussion

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions