storybook: [Bug]: TypeError: importers[path] is not a function occurred in monorepo after migrating to v7

Describe the bug

When using Storybook version 6.5.15 in monorepo with vite, there were no issues. But after migrating to version 7, an error occurred.

image

TypeError: importers[path] is not a function
    at StoryStore.importFn (http://localhost:6007/virtual:/@storybook/builder-vite/storybook-stories.js:6:31)
    at StoryStore.loadCSFFileByStoryId (http://localhost:6007/sb-preview/runtime.mjs:40:8376)
    at StoryStore.loadStory (http://localhost:6007/sb-preview/runtime.mjs:40:9563)
    at async http://localhost:6007/sb-preview/runtime.mjs:74:9003
    at async StoryRender.runPhase (http://localhost:6007/sb-preview/runtime.mjs:74:8764)
    at async StoryRender.prepare (http://localhost:6007/sb-preview/runtime.mjs:74:8922)
    at async PreviewWeb.renderSelection (http://localhost:6007/sb-preview/runtime.mjs:94:3120)
    at async PreviewWeb.selectSpecifiedStory (http://localhost:6007/sb-preview/runtime.mjs:94:247)

To Reproduce

clone https://github.com/emewjin/sb-bug-reproduce-project and following README steps

System

Environment Info:

  System:
    OS: macOS 13.2.1
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 16.19.1 - ~/.nvm/versions/node/v16.19.1/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.19.3 - ~/.nvm/versions/node/v16.19.1/bin/npm
  Browsers:
    Chrome: 112.0.5615.49
    Firefox: 107.0
    Safari: 16.3
  npmPackages:
    @storybook/addon-actions: ^7.0.4 => 7.0.4 
    @storybook/addon-backgrounds: ^7.0.4 => 7.0.4 
    @storybook/addon-controls: ^7.0.4 => 7.0.4 
    @storybook/addon-docs: ^7.0.4 => 7.0.4 
    @storybook/addon-interactions: ^7.0.4 => 7.0.4 
    @storybook/addon-links: ^7.0.4 => 7.0.4 
    @storybook/addon-mdx-gfm: ^7.0.4 => 7.0.4 
    @storybook/addon-measure: ^7.0.4 => 7.0.4 
    @storybook/addon-outline: ^7.0.4 => 7.0.4 
    @storybook/addon-toolbars: ^7.0.4 => 7.0.4 
    @storybook/addon-viewport: ^7.0.4 => 7.0.4 
    @storybook/mdx2-csf: ^1.0.0 => 1.0.0 
    @storybook/react: ^7.0.4 => 7.0.4 
    @storybook/react-vite: ^7.0.4 => 7.0.4 
    @storybook/testing-library: ^0.1.0 => 0.1.0 
    @storybook/theming: ^7.0.4 => 7.0.4

Additional context

No response

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 15
  • Comments: 17 (1 by maintainers)

Most upvoted comments

actually what worked for was just to restart/re-run the npm run storybook and it fixed the issue

I solve this problem when add a @ in config.stories. storybook v7.6.3

+ stories: ['../packages/lots-ui/lots/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
- stories: ['../packages/lots-ui/lots/**/*.stories.(js|jsx|mjs|ts|tsx)'],

I solve this problem when add a @ in config.stories. storybook v7.6.3

  • stories: [‘…/packages/lots-ui/lots/**/*.stories.@(js|jsx|mjs|ts|tsx)’],
  • stories: [‘…/packages/lots-ui/lots/**/*.stories.(js|jsx|mjs|ts|tsx)’],

tried the same method but it’s not working for me. this error always trigger when i add new stories, and thus i must restart CLI every single time a story is added.

importers[path] is not a function

importFn@http://localhost:6006/virtual:/@storybook/builder-vite/storybook-stories.js?t=1739338587575:61:31
loadEntry@http://localhost:6006/sb-preview/runtime.js:106:10136

The files path glob is very sensitive, so the following works:

'*.{md,mdx}', but the above *.(md|mdx) does NOT.

I solve this problem when add a @ in config.stories. storybook v7.6.3

+ stories: ['../packages/lots-ui/lots/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
- stories: ['../packages/lots-ui/lots/**/*.stories.(js|jsx|mjs|ts|tsx)'],

This worked for me! Thaks @KonghaYao! 👍

This issue keeps happening on my mac. forcing me to restart storybook 😕

I especially notice it when creating files and renaming them. Or when changing branches which results in a bunch of stories being removed / added.

Coworkers are starting to no longer use storybook “Because it never works”. I’ve been the strongest advocate for it at my place for years, and it really pains me when I understand their struggle and kinda understand that it’s no longer a tool that speeds them up.

If anyone has pointer regarding where the root cause might be, I’m willing to try to take a stab at it.

Experience same issue only on MacOS. Tried existing and clean vite project - same issue.

But it is working fine on linux.

@AIA-UnKNOWN worked for me!!!