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

Stories with async functions as properties throw "exports is not defined" in production #42

Closed
penx opened this issue Sep 29, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@penx
Copy link

penx commented Sep 29, 2022

Describe the bug

(original storybook issue here storybookjs/storybook#19290)

When @storybook/addon-react-native-web is used, yarn build-storybook will not show stories that contain a story with a .play function/interaction (using @storybook/addon-interactions).

There are no errors during build, but an error does appear in the console when running the built storybook:

Unexpected error while loading ./stories/Page.stories.tsx: exports is not defined
 ReferenceError: exports is not defined
    at ./src/stories/Page.stories.tsx (http://localhost:6006/main.52cda89e.iframe.bundle.js:1:11360)

These stories are visible when you run yarn storybook but not shown when you run yarn build-storybook.

Note, this is not restricted to interactions, it seems the same bug exists for any async function added as a property to the story,

i.e.

// no issue
MyStory.anything = () => {};

// causes story to be excluded when addon-react-native-web is used
MyStory.anything = async () => {};

To Reproduce

https://github.com/penx/storybook-bug-play-build

  • clone repo
  • yarn && yarn build-storybook && npx http-server storybook-static --port 6006

then:

  • note that the "Page" stories are no longer visible (see screenshot), as one of them has a play function
  • note that if you yarn storybook, these stories are still visible
  • note that if you remove the play function from the Page stories, they are visible again
  • note that building with yarn build-storybook --loglevel silly produces no errors or warnings other than what is visible in the repro-base

Additional context

Screenshot of repro storybook with "Pages" missing:

Screenshot 2022-09-29 at 12 48 30

Possibly related:

@dannyhw
Copy link
Member

dannyhw commented Sep 30, 2022

@penx thanks for the detailed issue, I'm away right now but once I get back I'll look into this.

@dannyhw
Copy link
Member

dannyhw commented Nov 22, 2022

@penx sorry for the delay in responding, did you find any solution?

@penx
Copy link
Author

penx commented Nov 22, 2022

No problem! I think we removed this addon and configured react-native-web manually

@dannyhw
Copy link
Member

dannyhw commented Nov 22, 2022

@penx could you share the config that worked? maybe there is something we could include in the package to resolve the issue.

@penx
Copy link
Author

penx commented Nov 22, 2022

As far as I understand, we're just using @storybook/preset-create-react-app then adding a webpack alias from react-native to react-native-web in the webpackFinal export of .storybook/main.js

@dannyhw
Copy link
Member

dannyhw commented Feb 3, 2023

Closing this since I'm not sure how to reproduce and it seems like you've found a different solution. If you would like to reopen just let me know.

@dannyhw dannyhw closed this as completed Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants