storybook icon indicating copy to clipboard operation
storybook copied to clipboard

[Bug]: [7.0.0-beta.20]: Unable to change story loading globing parttern for something else than `stories`

Open JUNNNI opened this issue 2 years ago • 4 comments

Describe the bug

Trying to update the story loading configuration with a globing pattern that doesn't contain the keyword stories. After updating that configuration, Storybook won't start and results into the following error:

Error: No matching story indexer found for `src/components/storybook-example/ExampleButton.[customName].tsx`

To Reproduce

Based on the following configuration that is working :

├── .storybook
│   └── main.ts
├── src
├── └── storybook-example
└─────── └── ExampleButton.stories.tsx
// .storybook/main.ts

import { ConfigEnv, mergeConfig } from 'vite';
import svgr from 'vite-plugin-svgr';
import { aliases } from '../src/aliases';

export default {
    stories: ['../src/**/*.mdx', '../src/**/*.stories.@(jsx|tsx)'],
    addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/addon-interactions'],
    framework: {
        name: '@storybook/react-vite',
        options: {},
    },
    docs: {
        autodocs: 'tag',
    },
    async viteFinal(config: ConfigEnv) {
        return mergeConfig(config, {
            plugins: [svgr()],
        });
    },
};
  1. Update the stories entry for something different, like follow:
stories: ['../src/**/*.mdx', '../src/**/*.storiestest.@(jsx|tsx)'],
  1. Rename ExampleButton.stories.tsx to ExampleButton.storiestest.tsx

  2. Restart Storybook and the following error will appear:

Error: No matching story indexer found for /Users/xxx/Documents/myproject/apps/client/src/components/storybook-example/ExampleButton.storiestest.tsx
    at StoryIndexGenerator.extractStories (/Users/xxx/Documents/myproject/node_modules/.pnpm/@[email protected]/node_modules/@storybook/core-server/dist/index.js:10:10111)

System

MacOS Monterey 12.5.1
pnpm version 7.17.1

Additional context

  • The project is a monorepo using pnpm and its workspaces features.
  • Tried to clear the node_modules/.cache folder after updating the configuration.

JUNNNI avatar Jan 03 '23 11:01 JUNNNI

This is the desired behavior. We use the file extension to determine the loading behavior of the file, e.g. .stories.ts are handled differently from .stories.js/.mdx/.stories.svelte. I think what's missing here is documentation on how to customize the indexing behavior for .storiestest.tsx. WDYT @jonniebigodes ?

shilman avatar Jan 03 '23 21:01 shilman

Thanks for your quick answer. Maybe my description was a bit ambiguous. I didn't want to talk about extensions but more about the file sufix before them. For example, I'd like storybook to look for [file].whatever.ts rather than [file].stories.ts. Notice that this change (as described above) was working properly before the latest beta version.

JUNNNI avatar Jan 04 '23 09:01 JUNNNI

@shilman any chance to reconsider that as a bug? 😃

JUNNNI avatar Jan 06 '23 14:01 JUNNNI

@shilman & @jonniebigodes I can take over this docs task. I already know of the issue and wrote about it @ https://sheriffmoose.medium.com/storybook-markdown-docs-not-mdx-part-2-757463fcad84

sheriffMoose avatar Jan 19 '23 04:01 sheriffMoose