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 play functions are excluded in production when using addon-react-native-web #19290

Closed
penx opened this issue Sep 29, 2022 · 2 comments

Comments

@penx
Copy link
Contributor

penx commented Sep 29, 2022

Describe the bug

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:

@penx penx changed the title Stories with play functions are silently excluded in production when using addon-react-native-web Stories with play functions are excluded in production when using addon-react-native-web Sep 29, 2022
@penx
Copy link
Contributor Author

penx commented Sep 29, 2022

After further investigation, I think this is due to @storybook/addon-react-native-web overriding the babel config in a way that is not compatible with async functions

https://github.com/storybookjs/addon-react-native-web/blob/main/src/webpack.ts

I have raised storybookjs/addon-react-native-web#42 as I now think that's where the issue is (or one of its dependencies)

@penx
Copy link
Contributor Author

penx commented Sep 29, 2022

Closing as I was able to resolve the issue by removing our dependency on @storybook/addon-react-native-web by configuring babel via customize-cra, react-app-rewired and config-overrides.js.

I have kept the upstream bug open.

@penx penx closed this as completed Sep 29, 2022
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