question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] StorybookConfig type does not recognize `viteFinal` as a property

See original GitHub issue

Describe the bug

I’ve written my Storybook config in TypeScript as a main.ts file instead of a main.js file, but the typings of StorybookConfig do not recognize viteFinal as a valid property.

[tsserver 2322] [E] Type '{ stories: string[]; staticDirs: string[]; addons: string[]; framework: string; core: { builder: string; }; features: { storyStoreV7: true; }; viteFinal(storybookDefaultConfig: Record<string, any>, { configType: _configType }: { ...; }): Promise<...>; }' is not assignable to type 'StorybookConfig'.
  Object literal may only specify known properties, and 'viteFinal' does not exist in type 'StorybookConfig'.

The definition for those types actually live in @storybook/core-common. I wasn’t sure whether to create this issue in the main repo or here, but figured this was more applicable.

Steps to reproduce the behavior

  1. Create a clean vite project
  2. Initialize latest storybook setup with npx sb@next init --builder @storybook/builder-vite
  3. Rename main.js to main.ts and try to assign the config object to the type of StorybookConfig.
  4. See type error.

Here is my example config in main.ts:

import type { StorybookConfig } from '@storybook/core-common'
import { mergeConfig } from 'vite'
import appViteConfig from '../vite.config'

const config: StorybookConfig = {
  stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
  staticDirs: ['../public'],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@storybook/addon-interactions',
  ],
  framework: '@storybook/react',
  core: {
    builder: '@storybook/builder-vite',
  },
  features: {
    storyStoreV7: true,
  },
  async viteFinal(
    storybookDefaultConfig: Record<string, any>,
    { configType: _configType }
  ) {
    // We combine Storybook's default Vite config with our own. Any Storybook
    // specific extensions are customized here as well.
    return mergeConfig(mergeConfig(storybookDefaultConfig, appViteConfig), {
      optimizeDeps: {
        // Including things here works around Vite/storybook prebundling issues
        // https://github.com/storybookjs/builder-vite/blob/70a9079fc2d545c046d63ff47666afdf8bb2810e/packages/builder-vite/README.md#known-issues
        include: ['msw-storybook-addon'],
      },
    })
  },
}

module.exports = config

Expected behavior

The viteFinal property should be a recognized property in the typings.

Screenshots and/or logs

N/A

Environment

  • OS: MacOS 12.0.1
  • Node.js version: 16.14.2
  • NPM version: 8.5.0
  • Browser (if applicable): N/A
  • Browser version (if applicable): N/A
  • Device (if applicable): MacBook Pro (14-inch, 2021)

Additional context

N/A

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
IanVScommented, Apr 29, 2022

This has been released in https://github.com/storybookjs/builder-vite/releases/tag/v0.1.32, thanks for the contribution, @dohooo!

1reaction
dohooocommented, Apr 22, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug] Builder error with typescript 4.7.4 · Issue #418 - GitHub
What version of vite are you using? ... and build-storybook commands and I got this error. ... import type { StorybookViteConfig } from ......
Read more >
How to resolve aliases in Storybook? - Stack Overflow
Couple things, resolve goes at the top-level of the webpack config, not under config.module . Not 100% sure about the webpack export/import ...
Read more >
Vite - Storybook
Storybook is a frontend workshop for building UI components and pages in isolation. Thousands of teams use it for UI development, testing, and...
Read more >
Using Vite for Bandler in Storybook | miyauci.me
Explains in detail the points where you can get stuck in a preact project. It also shows how to make the Storybook configuration...
Read more >
storybookjs/storybook (Raised $170.00) - Issuehunt
[Bug]: v7/csf3 stories are not recognized when functions generate the csf format ... known properties, and 'env' does not exist in type 'StorybookConfig'....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found