Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: If not export all members I can see the error "The requested module 'XXX' does not provide an export named 'XXXProps'" #29818

Open
zhaoyu1999 opened this issue Dec 5, 2024 · 3 comments

Comments

@zhaoyu1999
Copy link

zhaoyu1999 commented Dec 5, 2024

Describe the bug

If the ".stories.ts" file doesn't import the component directly but imports a file that exports the component, the storybook reports the error. I can reproduce this by using the generated demo. Here is what I did:

  • After executing the npx storybook@latest init, create a file "import.ts" under the ".stories" file with the content export {Button, ButtonProps} from "./Button";.
  • Then change the "Button.stories.ts" file to import from the "import.ts" instead of the "Button.tsx".
  • Run npm run storybook and open the Button story, you will see the error "The requested module '/stories/Button.tsx' does not provide an export named 'ButtonProps'".

If I change the "import.ts" to export * from "./Button", then everything works.

This only occurs when using typescript.

Reproduction link

https://github.com/zhaoyu1999/storybook-test

Reproduction steps

  1. Checkout the repo.
  2. Run npm run storybook
  3. Go to the "Button" stories.

System

Storybook Environment Info:

  System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
  Binaries:
    Node: 18.12.0 - C:\Libs\node18.12.0\node.EXE
    npm: 8.19.2 - C:\Libs\node18.12.0\npm.CMD <----- active
  Browsers:
    Edge: Chromium (127.0.2651.74)
  npmPackages:
    @storybook/addon-essentials: ^8.4.6 => 8.4.6
    @storybook/addon-interactions: ^8.4.6 => 8.4.6
    @storybook/addon-onboarding: ^8.4.6 => 8.4.6
    @storybook/blocks: ^8.4.6 => 8.4.6
    @storybook/react: ^8.4.6 => 8.4.6
    @storybook/react-vite: ^8.4.6 => 8.4.6
    @storybook/test: ^8.4.6 => 8.4.6
    storybook: ^8.4.6 => 8.4.6

Additional context

No response

@zhaoyu1999
Copy link
Author

Can someone assist me with this?

@zhaoyu1999
Copy link
Author

Another thing I noticed: the definition of "ButtonProps" is not included in the "Button.tsx" content. Maybe this is related to the Vite?

Image

@zhaoyu1999
Copy link
Author

I figured this out. The "ButtonProps" should be exported as a type. Changing "import.ts" to

export { Button } from "./Button ";
export type { ButtonProps } from "./Button ";

It will resolve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant